aoc21/d4/p1.go
2022-02-22 01:55:00 +02:00

30 lines
547 B
Go

package d4
import (
"strconv"
"strings"
)
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
}
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)
}