-
Notifications
You must be signed in to change notification settings - Fork 0
/
day6_part1.go
47 lines (39 loc) · 880 Bytes
/
day6_part1.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
package day6_part1
import (
"strings"
"GoAdventOfCode/util"
)
func getTheNumber(lines []string) int {
sum := 1
times := make([]int, 0)
lineTimes := strings.TrimPrefix(lines[0], "Time:")
timesRaw := strings.Fields(lineTimes)
for _, num := range timesRaw {
times = append(times, util.ConvertStringToInt(num))
}
distances := make([]int, 0)
lineDistances := strings.TrimPrefix(lines[1], "Distance:")
distancesRaw := strings.Fields(lineDistances)
for _, num := range distancesRaw {
distances = append(distances, util.ConvertStringToInt(num))
}
for n := range times {
count := 0
for i := 0; i <= times[n]; i++ {
distance := countDistance(i, times[n])
if distance > distances[n] {
count++
}
}
sum = sum * count
}
return sum
}
func countDistance(t1 int, t2 int) int {
v := t1
d := 0
for i := 0; i < t2-t1; i++ {
d += v
}
return d
}