-
Notifications
You must be signed in to change notification settings - Fork 0
/
day02.go
51 lines (43 loc) · 1.07 KB
/
day02.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
50
51
package main
import (
"fmt"
"strconv"
"strings"
)
func day02() {
lines := getLines("input/02.txt")
var sum, powersum int
for _, line := range lines {
const rmax, gmax, bmax = 12, 13, 14
possible := true
var rmin, gmin, bmin = 0, 0, 0
split := strings.Split(line, ":")
id, _ := strconv.Atoi(strings.Fields(split[0])[1])
split = strings.Split(split[1], ";")
for _, set := range split {
draw := strings.Split(set, ",")
for _, colorDraw := range draw {
colorAmount := strings.Fields(strings.TrimSpace(colorDraw))
amount, _ := strconv.Atoi(colorAmount[0])
color := colorAmount[1]
switch color {
case "red":
possible = possible && !(amount > rmax)
rmin = max(rmin, amount)
case "green":
possible = possible && !(amount > gmax)
gmin = max(gmin, amount)
case "blue":
possible = possible && !(amount > bmax)
bmin = max(bmin, amount)
}
}
}
if possible {
sum += id
}
powersum += rmin * gmin * bmin
}
fmt.Println("Day 02 Part 1 Result: ", sum)
fmt.Println("Day 02 Part 2 Result: ", powersum)
}