Compare commits
No commits in common. "0b67ae4aad4124c56748ab8f4e8af25ee5b7b701" and "d78e3eed864a915842fad59fde1ab00e02635b8e" have entirely different histories.
0b67ae4aad
...
d78e3eed86
6
main.go
6
main.go
|
@ -18,12 +18,6 @@ func main() {
|
||||||
|
|
||||||
runAndBenchmark("04", "1", false, solutions.Day04Part01)
|
runAndBenchmark("04", "1", false, solutions.Day04Part01)
|
||||||
runAndBenchmark("04", "2", false, solutions.Day04Part02)
|
runAndBenchmark("04", "2", false, solutions.Day04Part02)
|
||||||
|
|
||||||
runAndBenchmark("05", "1", false, solutions.Day05Part01)
|
|
||||||
runAndBenchmark("05", "2", false, solutions.Day05Part02)
|
|
||||||
|
|
||||||
runAndBenchmark("06", "1", false, solutions.Day06Part01)
|
|
||||||
runAndBenchmark("06", "2", false, solutions.Day06Part02)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type execute func(bool) int
|
type execute func(bool) int
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
package solutions
|
|
||||||
|
|
||||||
import (
|
|
||||||
"slices"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func seatStrToSeatId(seat string) int {
|
|
||||||
rowStr := seat[:7]
|
|
||||||
rowStr = strings.ReplaceAll(rowStr, "F", "0")
|
|
||||||
rowStr = strings.ReplaceAll(rowStr, "B", "1")
|
|
||||||
columnStr := seat[7:]
|
|
||||||
columnStr = strings.ReplaceAll(columnStr, "L", "0")
|
|
||||||
columnStr = strings.ReplaceAll(columnStr, "R", "1")
|
|
||||||
|
|
||||||
row, _ := strconv.ParseInt(rowStr, 2, 64)
|
|
||||||
column, _ := strconv.ParseInt(columnStr, 2, 64)
|
|
||||||
|
|
||||||
return int(row*8 + column)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Day05Part01(isTest bool) int {
|
|
||||||
input := ReadInput("05", isTest)
|
|
||||||
seats := strings.Split(input, "\n")
|
|
||||||
|
|
||||||
highestSeatId := 0
|
|
||||||
|
|
||||||
for _, seat := range seats {
|
|
||||||
seatId := seatStrToSeatId(seat)
|
|
||||||
if seatId > highestSeatId {
|
|
||||||
highestSeatId = seatId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return highestSeatId
|
|
||||||
}
|
|
||||||
|
|
||||||
func Day05Part02(isTest bool) int {
|
|
||||||
input := ReadInput("05", isTest)
|
|
||||||
seats := strings.Split(input, "\n")
|
|
||||||
seatsAmount := len(seats)
|
|
||||||
|
|
||||||
seatIds := make([]int, seatsAmount)
|
|
||||||
|
|
||||||
for i, seat := range seats {
|
|
||||||
seatId := seatStrToSeatId(seat)
|
|
||||||
seatIds[i] = seatId
|
|
||||||
}
|
|
||||||
|
|
||||||
slices.Sort(seatIds)
|
|
||||||
|
|
||||||
for i := 0; i < seatsAmount-1; i++ {
|
|
||||||
el1 := seatIds[i]
|
|
||||||
el2 := seatIds[i+1]
|
|
||||||
|
|
||||||
if el2-el1 == 2 {
|
|
||||||
return el1 + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
package solutions
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Day06Part01(isTest bool) int {
|
|
||||||
input := ReadInput("06", isTest)
|
|
||||||
groups := strings.Split(input, "\n\n")
|
|
||||||
|
|
||||||
sum := 0
|
|
||||||
|
|
||||||
for _, group := range groups {
|
|
||||||
frequency := make(map[rune]int)
|
|
||||||
|
|
||||||
for _, letter := range group {
|
|
||||||
// remove non a-z character
|
|
||||||
if letter < 97 || letter > 122 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
previousValue, _ := frequency[letter]
|
|
||||||
frequency[letter] = previousValue + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
sum += len(frequency)
|
|
||||||
}
|
|
||||||
|
|
||||||
return sum
|
|
||||||
}
|
|
||||||
|
|
||||||
func Day06Part02(isTest bool) int {
|
|
||||||
input := ReadInput("06", isTest)
|
|
||||||
groups := strings.Split(input, "\n\n")
|
|
||||||
|
|
||||||
sum := 0
|
|
||||||
|
|
||||||
for _, group := range groups {
|
|
||||||
persons := strings.Split(group, "\n")
|
|
||||||
personAmount := len(persons)
|
|
||||||
|
|
||||||
frequency := make(map[rune]int)
|
|
||||||
|
|
||||||
for _, person := range persons {
|
|
||||||
for _, letter := range person {
|
|
||||||
previousValue, _ := frequency[letter]
|
|
||||||
frequency[letter] = previousValue + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, value := range frequency {
|
|
||||||
if value == personAmount {
|
|
||||||
sum += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sum
|
|
||||||
}
|
|
Loading…
Reference in New Issue