Day 5 part 1
This commit is contained in:
parent
d78e3eed86
commit
531b8a52ef
3
main.go
3
main.go
@ -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
40
solutions/day05.go
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user