@@ -9,13 +9,14 @@ import (
9
9
10
10
func main () {
11
11
lines := common .ReadAllLines ("../2023-go/day02/input.txt" )
12
+ games := readGames (lines )
12
13
log .Println ("Day 02 Part 01" )
13
- partOne (lines )
14
+ partOne (games )
14
15
log .Println ("Day 02 Part 02" )
16
+ partTwo (games )
15
17
}
16
18
17
- func partOne (lines []string ) {
18
- games := readGames (lines )
19
+ func partOne (games []game ) {
19
20
possibleGames := countPossibleGames (games )
20
21
log .Println (possibleGames )
21
22
}
@@ -39,6 +40,33 @@ func isGamePossible(game game) bool {
39
40
return true
40
41
}
41
42
43
+ func partTwo (games []game ) {
44
+ var sum int
45
+ for _ , game := range games {
46
+ sub := findMinimumSubset (game )
47
+ sum += sub .red * sub .green * sub .blue
48
+ }
49
+ log .Println (sum )
50
+ }
51
+
52
+ func findMinimumSubset (game game ) subset {
53
+ minimumSubset := subset {red : 0 , green : 0 , blue : 0 } // start low to find the minimum
54
+ for _ , subset := range game .subsets {
55
+ if subset .green > minimumSubset .green {
56
+ minimumSubset .green = subset .green
57
+ }
58
+ if subset .red > minimumSubset .red {
59
+ minimumSubset .red = subset .red
60
+ }
61
+ if subset .blue > minimumSubset .blue {
62
+ minimumSubset .blue = subset .blue
63
+ }
64
+ }
65
+ return minimumSubset
66
+ }
67
+
68
+ // ------- Helper functions to parse the input lines into structs of games and subsets -------
69
+
42
70
type game struct {
43
71
id int
44
72
subsets []subset
0 commit comments