-
Notifications
You must be signed in to change notification settings - Fork 0
/
day6.go
41 lines (37 loc) · 745 Bytes
/
day6.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
package main
import (
"strings"
)
func day6(input string) int {
times := []int{}
distances := []int{}
// format the data
fromInput(input, func(line string) {
parts := strings.Split(line, ":")
values := parseNumberSuits(parts[1])
if strings.Contains(parts[0], "Time") {
times = values
}
if strings.Contains(parts[0], "Distance") {
distances = values
}
})
total := 1
for i, t := range times {
nbWaysToWin := 0
for nbMilli := range t {
// distance = nb millisecond to run * nb milliseconds holds
dist := (t - nbMilli) * nbMilli
if dist > distances[i] {
nbWaysToWin++
}
}
if nbWaysToWin != 0 {
total *= nbWaysToWin
}
}
return total
}
func day6_2(input string) int {
return day6(input)
}