-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04p2.odin
51 lines (42 loc) · 1.03 KB
/
04p2.odin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import "core:fmt"
import "core:strings"
D04P2 :: proc() {
input_string := #load("./inputs/04.txt", string)
lines := strings.split(input_string, "\n", context.temp_allocator)
winning_score := get_last_bingo_winner_score(lines)
fmt.printfln("Last bingo winner score: %d", winning_score)
}
get_last_bingo_winner_score :: proc(input: []string) -> int {
drawings := parse_bingo_drawings(input)
cards: [dynamic]bingo_card
defer delete(drawings)
defer delete(cards)
for i := 2; i < len(input); i += 6 {
append(&cards, parse_bingo_card(input[i:i + 5]))
}
current_card := 0
winning_card: int
winning_drawing := 0
for drawing in drawings {
for &card in cards {
if card.won {
continue
}
for &row in card.numbers {
for &number in row {
if number.number == drawing {
number.drawn = true
}
}
}
current_card = check_bingo(card)
if current_card != 0 {
card.won = true
winning_card = current_card
winning_drawing = drawing
}
}
}
return winning_card * winning_drawing
}