Day 5 part 1

master
Araozu 2024-03-01 09:05:46 -05:00
parent d78e3eed86
commit 531b8a52ef
2 changed files with 43 additions and 0 deletions

View File

@ -18,6 +18,9 @@ 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", true, solutions.Day05Part02)
} }
type execute func(bool) int type execute func(bool) int

40
solutions/day05.go Normal file
View File

@ -0,0 +1,40 @@
package solutions
import (
"regexp"
"strconv"
"strings"
)
func seatToValue(seat string) (int, int, int) {
lowRegex := regexp.MustCompile("[FL]")
highRegex := regexp.MustCompile("[BR]")
seatStr := lowRegex.ReplaceAllString(seat, "0")
seatStr = highRegex.ReplaceAllString(seatStr, "1")
row, _ := strconv.ParseInt(seatStr[:7], 2, 64)
column, _ := strconv.ParseInt(seatStr[7:], 2, 64)
return int(row), int(column), 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 := seatToValue(seat)
if seatId > highestSeatId {
highestSeatId = seatId
}
}
return highestSeatId
}
func Day05Part02(isTest bool) int {
return -1
}