-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (41 loc) · 768 Bytes
/
main.go
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
package main
import (
"fmt"
"strings"
"github.com/Alex-Waring/AoC/utils"
)
type State map[int]int
func solve(input []string, days int) {
defer utils.Timer("part1")()
state := State{}
// Load State
for _, age := range strings.Split(input[0], ",") {
i := utils.IntegerOf(age)
state[i]++
}
for day := 1; day <= days; day++ {
new_state := State{}
for age, count := range state {
if age == 0 {
// Reset
new_state[6] += count
// Birth
new_state[8] += count
} else {
// Age
new_state[age-1] += count
}
}
state = new_state
}
total := 0
for _, count := range state {
total += count
}
fmt.Println("Total: ", total)
}
func main() {
input := utils.ReadInput("input.txt")
solve(input, 80)
solve(input, 256)
}