2022-02-21 22:28:30 +02:00
|
|
|
package d4
|
|
|
|
|
|
|
|
import (
|
2022-02-22 01:55:00 +02:00
|
|
|
"strconv"
|
2022-02-21 22:28:30 +02:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2022-02-22 01:55:00 +02:00
|
|
|
func findBingo(boards []board, takes []string) (board, int) {
|
|
|
|
|
|
|
|
for _, take := range takes {
|
|
|
|
converted, _ := strconv.Atoi(take)
|
|
|
|
for _, board := range boards {
|
|
|
|
marked := markBoard(board, converted)
|
|
|
|
if gotBingo(marked) {
|
|
|
|
return marked, converted
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, 0
|
|
|
|
}
|
|
|
|
|
2022-02-21 22:28:30 +02:00
|
|
|
func P1(input string) int {
|
|
|
|
lines := strings.Split(input, "\n\n")
|
|
|
|
takes := strings.Split(lines[0], ",")
|
|
|
|
boards := createBoards(lines[1:])
|
|
|
|
bingo, take := findBingo(boards, takes)
|
|
|
|
|
|
|
|
return score(bingo, take)
|
|
|
|
}
|