2023 Day 2 Complete!
This commit is contained in:
parent
d9aba1bd1f
commit
6b509c7926
100
2023/day02/input
Normal file
100
2023/day02/input
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
Game 1: 3 blue, 2 green, 6 red; 17 green, 4 red, 8 blue; 2 red, 1 green, 10 blue; 1 blue, 5 green
|
||||||
|
Game 2: 9 red, 2 green; 5 red, 1 blue, 6 green; 3 green, 13 red, 1 blue; 3 red, 6 green; 1 blue, 14 red, 6 green
|
||||||
|
Game 3: 6 red, 3 blue, 8 green; 6 blue, 12 green, 15 red; 3 blue, 18 green, 4 red
|
||||||
|
Game 4: 1 blue, 4 red; 2 blue, 6 red; 13 blue; 11 blue, 1 green, 8 red; 10 blue, 3 green, 2 red; 3 green, 7 blue
|
||||||
|
Game 5: 2 red, 1 blue, 8 green; 2 blue, 7 green, 3 red; 1 blue, 7 green, 4 red; 2 blue, 1 green, 1 red; 13 green, 1 blue
|
||||||
|
Game 6: 7 green, 1 red, 3 blue; 1 red, 4 blue; 6 green, 6 blue; 8 green, 1 red; 6 green, 1 red, 5 blue
|
||||||
|
Game 7: 10 blue, 1 green; 5 red, 8 blue, 3 green; 11 blue, 5 red, 8 green; 2 blue, 8 red, 5 green; 7 blue, 9 green; 6 blue, 2 green, 7 red
|
||||||
|
Game 8: 15 green, 8 blue, 3 red; 6 blue, 7 green, 5 red; 2 green, 1 red, 5 blue; 9 blue, 9 green, 5 red
|
||||||
|
Game 9: 16 red; 5 blue, 6 red, 9 green; 7 blue, 6 green, 2 red; 15 red, 5 blue, 3 green; 1 red, 6 green, 6 blue; 3 blue, 7 red, 5 green
|
||||||
|
Game 10: 17 green, 5 blue, 6 red; 18 green, 9 red; 4 red, 4 blue, 4 green; 10 red, 6 green, 5 blue; 8 red, 4 blue, 12 green
|
||||||
|
Game 11: 4 blue, 2 green, 5 red; 1 blue, 1 red; 9 blue, 1 green, 2 red; 4 red, 10 blue; 3 green, 4 blue, 3 red
|
||||||
|
Game 12: 4 green, 2 blue, 7 red; 4 blue, 2 green, 1 red; 7 green, 5 blue, 9 red
|
||||||
|
Game 13: 1 green, 3 red, 3 blue; 1 blue, 10 green; 2 green, 3 blue
|
||||||
|
Game 14: 7 red, 3 green, 12 blue; 5 red, 4 green, 6 blue; 13 blue, 1 red; 4 blue, 6 red, 2 green; 4 red, 3 blue; 9 red, 13 blue
|
||||||
|
Game 15: 4 blue, 5 red, 2 green; 7 red, 2 blue, 1 green; 17 red, 3 blue; 2 blue; 4 blue, 8 red
|
||||||
|
Game 16: 5 blue; 9 red, 14 green, 5 blue; 5 blue, 9 green
|
||||||
|
Game 17: 3 blue, 5 red; 6 blue, 1 green, 4 red; 7 green, 6 blue, 7 red; 1 red, 6 blue, 4 green; 6 green; 1 blue, 6 green
|
||||||
|
Game 18: 9 blue, 4 green, 2 red; 1 green, 9 red, 10 blue; 14 red, 10 green, 17 blue; 12 red, 1 green, 15 blue; 3 blue, 8 red, 2 green; 3 green, 11 red, 13 blue
|
||||||
|
Game 19: 1 blue, 3 red, 9 green; 14 green, 3 red, 2 blue; 1 blue, 8 red, 11 green; 4 blue, 3 red; 14 red, 4 green; 5 red, 8 green
|
||||||
|
Game 20: 2 blue, 3 red, 2 green; 3 blue, 2 green; 1 red, 4 green, 5 blue; 9 blue, 9 green, 3 red; 3 green, 1 blue, 4 red; 1 red, 9 green, 2 blue
|
||||||
|
Game 21: 11 blue, 6 red; 8 red; 7 red, 6 green, 11 blue; 7 green, 7 red, 11 blue; 6 red, 12 blue
|
||||||
|
Game 22: 7 green, 8 blue, 5 red; 12 green, 4 red, 2 blue; 12 green, 7 red, 11 blue
|
||||||
|
Game 23: 5 green, 2 blue, 7 red; 6 blue, 8 green, 3 red; 10 red, 5 blue; 6 green, 3 blue; 1 green, 8 red
|
||||||
|
Game 24: 17 blue, 1 green, 2 red; 2 red, 11 green, 9 blue; 6 red, 8 blue
|
||||||
|
Game 25: 3 red, 1 blue, 19 green; 1 blue, 1 green, 6 red; 6 green, 5 blue; 4 green, 2 red, 19 blue; 6 red, 19 blue, 18 green; 1 red, 4 blue, 1 green
|
||||||
|
Game 26: 3 red, 4 blue, 2 green; 2 red, 1 green, 3 blue; 14 blue, 1 green, 3 red; 5 green, 2 red, 10 blue; 9 blue, 2 red, 7 green; 15 blue, 4 green, 3 red
|
||||||
|
Game 27: 3 blue, 5 red, 2 green; 6 red, 7 blue, 9 green; 14 green, 11 red, 6 blue; 3 blue, 20 green, 3 red; 6 red, 15 green, 7 blue; 13 red, 1 blue, 14 green
|
||||||
|
Game 28: 4 blue, 7 green, 4 red; 2 red, 4 blue, 7 green; 6 blue, 11 green, 4 red; 6 blue, 6 green, 3 red; 6 green, 12 red
|
||||||
|
Game 29: 3 red, 9 blue; 5 red, 5 blue; 2 green, 3 red, 3 blue
|
||||||
|
Game 30: 1 green, 1 red, 3 blue; 1 blue, 1 red, 3 green; 1 blue; 1 blue, 3 green, 1 red; 2 blue, 2 green
|
||||||
|
Game 31: 2 blue, 1 red; 1 blue, 1 green, 1 red; 4 blue, 3 green; 1 red, 3 green, 2 blue; 2 green
|
||||||
|
Game 32: 1 blue, 6 green; 9 red, 6 green; 1 blue, 15 red, 3 green
|
||||||
|
Game 33: 18 green, 1 blue, 10 red; 10 red, 1 blue, 7 green; 11 green; 6 red, 13 green
|
||||||
|
Game 34: 10 red, 14 blue, 6 green; 2 green, 13 blue, 1 red; 8 green, 7 blue, 1 red; 9 blue, 7 green, 4 red
|
||||||
|
Game 35: 5 blue, 9 green, 2 red; 7 green, 9 blue, 5 red; 1 green, 5 red
|
||||||
|
Game 36: 10 red; 5 red, 1 green, 1 blue; 2 green, 8 red; 9 red, 2 green; 1 blue, 10 red; 6 red, 1 green, 1 blue
|
||||||
|
Game 37: 13 red, 1 blue, 7 green; 1 green, 9 red, 3 blue; 4 red, 1 blue, 11 green; 1 red; 1 red, 1 blue; 6 red, 3 blue, 2 green
|
||||||
|
Game 38: 3 blue, 12 red, 7 green; 1 green; 12 red, 1 blue
|
||||||
|
Game 39: 7 green, 12 blue, 2 red; 3 red, 10 blue, 7 green; 2 red, 8 green, 3 blue; 3 red, 12 blue, 5 green
|
||||||
|
Game 40: 7 green, 5 red; 1 green, 2 blue; 2 red, 1 green, 7 blue
|
||||||
|
Game 41: 1 red, 7 green, 2 blue; 2 green, 2 blue; 4 blue, 7 green, 1 red; 1 blue, 1 red, 7 green; 6 blue, 2 red, 3 green
|
||||||
|
Game 42: 6 blue; 4 green, 18 blue, 1 red; 10 green, 14 blue, 2 red; 6 blue, 4 green; 2 red, 13 blue, 6 green; 6 green, 1 red, 5 blue
|
||||||
|
Game 43: 5 blue, 12 red; 5 blue, 2 green, 7 red; 9 red, 4 blue; 1 green, 11 red, 2 blue; 5 red, 1 green; 2 blue, 3 red, 1 green
|
||||||
|
Game 44: 4 blue, 9 red, 4 green; 4 blue, 10 red; 4 green, 5 red; 1 green, 2 red, 3 blue
|
||||||
|
Game 45: 7 green, 2 blue, 18 red; 19 red, 7 green; 8 green, 1 blue, 19 red; 2 green, 12 red; 6 red, 5 green; 7 green, 10 red
|
||||||
|
Game 46: 1 blue, 15 red, 11 green; 7 red, 1 green, 5 blue; 13 red, 2 blue, 2 green; 7 green, 5 blue, 10 red; 12 green, 3 red, 1 blue
|
||||||
|
Game 47: 2 blue, 2 red, 5 green; 7 green, 2 red, 7 blue; 10 blue, 2 red, 8 green
|
||||||
|
Game 48: 8 green, 10 red; 6 green, 5 red; 12 green, 2 blue; 17 green, 5 red, 1 blue; 14 green, 3 blue, 16 red; 1 blue, 5 red
|
||||||
|
Game 49: 5 blue, 6 red, 12 green; 8 blue, 15 green; 4 blue, 3 green, 3 red; 6 red, 11 green, 10 blue; 9 green, 2 red, 10 blue
|
||||||
|
Game 50: 10 red, 11 green, 14 blue; 6 green, 8 blue, 17 red; 2 blue, 4 red; 6 blue, 8 green, 17 red; 17 red, 9 blue, 2 green; 13 blue, 16 red, 12 green
|
||||||
|
Game 51: 12 red, 2 green, 7 blue; 5 blue, 10 red; 1 blue, 7 red, 1 green; 14 blue, 2 red, 1 green
|
||||||
|
Game 52: 5 blue, 5 red, 8 green; 1 blue, 9 green, 7 red; 4 blue, 5 red, 3 green; 7 green, 2 blue, 2 red; 5 red, 3 blue, 17 green; 19 green, 1 red
|
||||||
|
Game 53: 4 red, 1 blue, 2 green; 1 green; 2 red; 1 blue, 2 green; 2 green, 4 red
|
||||||
|
Game 54: 7 red; 9 red, 2 blue, 14 green; 1 blue, 5 green; 7 green, 3 blue
|
||||||
|
Game 55: 11 blue, 2 green; 11 blue, 9 green, 12 red; 8 green, 6 blue, 12 red
|
||||||
|
Game 56: 2 green, 1 red, 2 blue; 4 red, 5 green, 5 blue; 5 red, 5 blue, 10 green; 8 red, 3 green, 3 blue
|
||||||
|
Game 57: 7 red, 3 green; 1 blue, 6 red, 1 green; 1 blue; 7 red, 1 green, 1 blue; 2 red, 1 blue, 1 green; 3 green, 1 blue
|
||||||
|
Game 58: 9 blue, 2 red; 2 green, 9 blue, 2 red; 5 blue, 4 green
|
||||||
|
Game 59: 8 red; 5 green, 1 blue, 3 red; 1 green, 8 red
|
||||||
|
Game 60: 9 green, 8 blue, 3 red; 10 green, 4 red; 8 blue, 2 green, 4 red; 1 red, 5 green, 7 blue; 1 green, 4 blue, 1 red; 4 blue
|
||||||
|
Game 61: 5 blue, 9 red, 4 green; 5 green, 7 blue, 6 red; 7 green, 8 red; 7 blue, 4 red, 2 green; 8 red, 4 blue, 5 green; 3 green, 9 red, 7 blue
|
||||||
|
Game 62: 9 red, 10 blue; 1 green, 7 red, 13 blue; 1 green, 11 blue; 6 red, 16 blue, 5 green; 20 red, 1 green, 3 blue
|
||||||
|
Game 63: 9 red, 8 green, 1 blue; 13 green, 12 red, 1 blue; 7 green, 5 red, 3 blue
|
||||||
|
Game 64: 3 red, 2 blue, 10 green; 3 green; 1 blue, 8 green, 2 red; 7 red, 1 blue, 4 green; 9 red, 1 blue, 4 green
|
||||||
|
Game 65: 7 red, 6 green; 1 blue, 4 green, 7 red; 6 red; 6 red, 4 green, 1 blue
|
||||||
|
Game 66: 4 blue, 4 green; 1 red, 7 green, 1 blue; 7 green, 3 red, 3 blue; 1 blue, 1 red, 6 green; 3 red, 7 green
|
||||||
|
Game 67: 5 green, 16 blue, 5 red; 4 red, 7 green, 3 blue; 4 red, 4 green, 9 blue; 12 green, 5 red; 15 green, 3 red; 10 blue, 6 red, 1 green
|
||||||
|
Game 68: 3 green, 3 blue, 5 red; 2 green, 6 blue; 2 green, 3 blue, 1 red; 1 blue, 11 red
|
||||||
|
Game 69: 5 green, 1 blue; 16 green, 9 red; 10 red, 18 green
|
||||||
|
Game 70: 1 blue, 1 green; 1 red; 1 red, 2 blue, 1 green; 1 green, 2 red; 2 blue, 2 red; 1 red
|
||||||
|
Game 71: 11 red; 2 green, 3 blue, 13 red; 1 green, 3 blue; 15 red, 1 green, 3 blue; 4 red
|
||||||
|
Game 72: 2 blue, 6 red, 18 green; 6 red, 8 green, 7 blue; 5 blue, 3 red, 12 green; 3 red, 2 blue, 4 green
|
||||||
|
Game 73: 12 blue, 7 green, 4 red; 5 green, 2 red, 4 blue; 3 green, 3 red, 10 blue; 1 green, 12 blue, 6 red; 3 blue, 6 green, 14 red
|
||||||
|
Game 74: 3 red; 1 blue, 8 green, 11 red; 3 green, 2 red
|
||||||
|
Game 75: 5 green, 2 red, 1 blue; 8 green, 2 red; 11 green, 2 red; 2 red, 17 green; 3 blue, 3 green, 2 red
|
||||||
|
Game 76: 1 blue, 5 green, 4 red; 8 green, 11 blue, 5 red; 8 blue, 2 red, 11 green
|
||||||
|
Game 77: 1 red, 11 blue, 7 green; 8 green, 4 blue; 1 blue, 8 green
|
||||||
|
Game 78: 1 green, 1 red, 1 blue; 3 green, 1 blue, 3 red; 10 green, 1 blue; 12 green
|
||||||
|
Game 79: 1 red, 11 blue, 6 green; 3 green, 3 red, 5 blue; 16 blue, 1 red, 5 green; 11 blue, 3 green, 2 red; 8 blue, 6 green, 4 red
|
||||||
|
Game 80: 5 green; 6 green, 7 red, 4 blue; 7 green, 5 blue; 6 blue, 6 green; 7 blue, 7 green; 6 green, 7 blue, 5 red
|
||||||
|
Game 81: 1 green, 14 blue; 11 blue, 1 red; 1 red, 16 green, 2 blue; 9 green, 1 red, 13 blue; 10 green, 8 blue
|
||||||
|
Game 82: 7 green, 7 red, 3 blue; 4 blue, 1 green, 4 red; 2 green, 14 blue, 3 red
|
||||||
|
Game 83: 15 blue; 2 blue, 1 green, 4 red; 8 green, 4 red, 6 blue
|
||||||
|
Game 84: 12 blue, 17 green; 6 green, 1 red, 16 blue; 1 blue, 1 red; 5 blue, 11 green
|
||||||
|
Game 85: 5 blue, 15 green, 3 red; 4 blue, 1 green, 11 red; 8 red, 2 blue, 4 green
|
||||||
|
Game 86: 11 blue, 16 green, 16 red; 11 blue, 17 red, 10 green; 8 green, 7 red
|
||||||
|
Game 87: 2 red, 4 green, 2 blue; 2 blue, 6 green; 2 red, 3 blue, 3 green; 1 red, 4 green; 1 green, 2 blue, 2 red; 4 blue, 4 green
|
||||||
|
Game 88: 10 red, 7 green; 2 blue, 6 red, 1 green; 8 blue, 8 red, 7 green; 2 green, 5 blue, 2 red; 3 blue, 3 red, 6 green
|
||||||
|
Game 89: 9 blue, 16 green; 2 red, 5 blue, 6 green; 12 blue, 15 green; 8 green, 2 red, 3 blue
|
||||||
|
Game 90: 18 red, 1 blue; 3 red, 5 blue, 4 green; 1 blue, 2 green, 6 red; 2 green, 16 red, 3 blue; 5 blue, 13 red, 5 green
|
||||||
|
Game 91: 4 red, 7 green, 1 blue; 3 green, 16 blue, 2 red; 4 green, 8 blue
|
||||||
|
Game 92: 4 red, 3 green; 5 red, 11 green, 1 blue; 16 green, 13 red; 15 green, 14 red, 3 blue; 3 red, 5 green, 2 blue
|
||||||
|
Game 93: 2 blue, 1 red, 3 green; 10 blue, 1 red, 10 green; 11 blue, 16 green, 4 red; 2 green, 20 blue, 7 red; 11 green, 8 red, 15 blue; 9 green, 10 blue, 1 red
|
||||||
|
Game 94: 2 blue, 12 red, 10 green; 16 red, 9 blue, 6 green; 5 green, 9 blue, 11 red; 4 red, 2 blue
|
||||||
|
Game 95: 2 green, 9 red, 1 blue; 2 blue, 1 red; 2 green, 5 blue, 3 red
|
||||||
|
Game 96: 1 green, 5 red, 13 blue; 1 green, 2 red, 13 blue; 2 green, 2 red, 17 blue; 3 red, 1 green; 6 red, 2 green; 1 green, 7 blue, 4 red
|
||||||
|
Game 97: 1 green, 1 red, 1 blue; 2 blue, 11 green; 1 blue, 13 green; 9 blue, 6 green, 1 red; 10 green, 8 blue
|
||||||
|
Game 98: 12 green, 9 red; 12 green, 10 blue, 3 red; 3 red, 13 green, 7 blue
|
||||||
|
Game 99: 8 green, 10 blue, 1 red; 10 green, 2 red, 6 blue; 3 green, 1 blue, 1 red; 10 blue, 1 red
|
||||||
|
Game 100: 8 blue, 6 green, 8 red; 7 red, 2 blue; 2 red, 10 green, 10 blue; 9 green, 7 red; 3 red, 7 green, 1 blue
|
117
2023/day02/main.go
Normal file
117
2023/day02/main.go
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
inp := h.StdinToStringSlice()
|
||||||
|
part1(inp)
|
||||||
|
part2(inp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func part1(input []string) {
|
||||||
|
allGames := parseAllGames(input)
|
||||||
|
var result int
|
||||||
|
for i := range allGames {
|
||||||
|
if allGames[i].getMost("red") > 12 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if allGames[i].getMost("green") > 13 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if allGames[i].getMost("blue") > 14 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
result += allGames[i].id
|
||||||
|
}
|
||||||
|
fmt.Println("# Part 1")
|
||||||
|
fmt.Println(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func part2(input []string) {
|
||||||
|
allGames := parseAllGames(input)
|
||||||
|
var result int
|
||||||
|
for i := range allGames {
|
||||||
|
result += allGames[i].getMinimumPower()
|
||||||
|
}
|
||||||
|
fmt.Println("# Part 2")
|
||||||
|
fmt.Println(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseAllGames(input []string) []Game {
|
||||||
|
allGames := []Game{}
|
||||||
|
for i := range input {
|
||||||
|
gameNo, r := parseGame(input[i])
|
||||||
|
allGames = append(allGames, Game{id: gameNo, pulls: r})
|
||||||
|
}
|
||||||
|
return allGames
|
||||||
|
}
|
||||||
|
|
||||||
|
type Pull struct {
|
||||||
|
subsets map[string]int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Pull) String() string {
|
||||||
|
ret := ""
|
||||||
|
for k, v := range p.subsets {
|
||||||
|
ret = fmt.Sprintf("%s%d %s, ", ret, v, k)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
type Game struct {
|
||||||
|
id int
|
||||||
|
pulls []Pull
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Game) getMost(color string) int {
|
||||||
|
max := h.MIN_INT
|
||||||
|
for i := range g.pulls {
|
||||||
|
if v, ok := g.pulls[i].subsets[color]; ok {
|
||||||
|
if v > max {
|
||||||
|
max = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Game) getMinimumPower() int {
|
||||||
|
maxRed := g.getMost("red")
|
||||||
|
maxBlue := g.getMost("blue")
|
||||||
|
maxGreen := g.getMost("green")
|
||||||
|
return maxRed * maxBlue * maxGreen
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g Game) String() string {
|
||||||
|
ret := fmt.Sprintf("Game %d: ", g.id)
|
||||||
|
for i := range g.pulls {
|
||||||
|
ret = fmt.Sprintf("%s%s; ", ret, g.pulls[i])
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func parsePulls(input string) Pull {
|
||||||
|
ret := Pull{subsets: make(map[string]int)}
|
||||||
|
pts := strings.Split(input, ",")
|
||||||
|
for i := range pts {
|
||||||
|
blocks := strings.Fields(pts[i])
|
||||||
|
ret.subsets[blocks[1]] = h.Atoi(blocks[0])
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
func parseGame(input string) (int, []Pull) {
|
||||||
|
res := []Pull{}
|
||||||
|
pts := strings.Split(input, ":")
|
||||||
|
gameNo := h.Atoi(strings.Fields(pts[0])[1])
|
||||||
|
pulls := strings.Split(pts[1], ";")
|
||||||
|
for i := range pulls {
|
||||||
|
res = append(res, parsePulls(pulls[i]))
|
||||||
|
}
|
||||||
|
|
||||||
|
return gameNo, res
|
||||||
|
}
|
109
2023/day02/problem
Normal file
109
2023/day02/problem
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen (AoC++) 4*
|
||||||
|
|
||||||
|
--- Day 2: Cube Conundrum ---
|
||||||
|
|
||||||
|
You're launched high into the atmosphere! The apex of your trajectory just barely reaches the surface of a large island
|
||||||
|
floating in the sky. You gently land in a fluffy pile of leaves. It's quite cold, but you don't see much snow. An Elf runs
|
||||||
|
over to greet you.
|
||||||
|
|
||||||
|
The Elf explains that you've arrived at Snow Island and apologizes for the lack of snow. He'll be happy to explain the
|
||||||
|
situation, but it's a bit of a walk, so you have some time. They don't get many visitors up here; would you like to play a
|
||||||
|
game in the meantime?
|
||||||
|
|
||||||
|
As you walk, the Elf shows you a small bag and some cubes which are either red, green, or blue. Each time you play this
|
||||||
|
game, he will hide a secret number of cubes of each color in the bag, and your goal is to figure out information about the
|
||||||
|
number of cubes.
|
||||||
|
|
||||||
|
To get information, once a bag has been loaded with cubes, the Elf will reach into the bag, grab a handful of random cubes,
|
||||||
|
show them to you, and then put them back in the bag. He'll do this a few times per game.
|
||||||
|
|
||||||
|
You play several games and record the information from each game (your puzzle input). Each game is listed with its ID number
|
||||||
|
(like the 11 in Game 11: ...) followed by a semicolon-separated list of subsets of cubes that were revealed from the bag
|
||||||
|
(like 3 red, 5 green, 4 blue).
|
||||||
|
|
||||||
|
For example, the record of a few games might look like this:
|
||||||
|
|
||||||
|
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||||
|
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||||
|
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||||
|
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||||
|
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
||||||
|
|
||||||
|
In game 1, three sets of cubes are revealed from the bag (and then put back again). The first set is 3 blue cubes and 4 red
|
||||||
|
cubes; the second set is 1 red cube, 2 green cubes, and 6 blue cubes; the third set is only 2 green cubes.
|
||||||
|
|
||||||
|
The Elf would first like to know which games would have been possible if the bag contained only 12 red cubes, 13 green
|
||||||
|
cubes, and 14 blue cubes?
|
||||||
|
|
||||||
|
In the example above, games 1, 2, and 5 would have been possible if the bag had been loaded with that configuration.
|
||||||
|
However, game 3 would have been impossible because at one point the Elf showed you 20 red cubes at once; similarly, game 4
|
||||||
|
would also have been impossible because the Elf showed you 15 blue cubes at once. If you add up the IDs of the games that
|
||||||
|
would have been possible, you get 8.
|
||||||
|
|
||||||
|
Determine which games would have been possible if the bag had been loaded with only 12 red cubes, 13 green cubes, and 14
|
||||||
|
blue cubes. What is the sum of the IDs of those games?
|
||||||
|
|
||||||
|
Your puzzle answer was 2727.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
The Elf says they've stopped producing snow because they aren't getting any water! He isn't sure why the water stopped;
|
||||||
|
however, he can show you how to get to the water source to check it out for yourself. It's just up ahead!
|
||||||
|
|
||||||
|
As you continue your walk, the Elf poses a second question: in each game you played, what is the fewest number of cubes of
|
||||||
|
each color that could have been in the bag to make the game possible?
|
||||||
|
|
||||||
|
Again consider the example games from earlier:
|
||||||
|
|
||||||
|
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||||
|
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||||
|
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||||
|
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||||
|
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
||||||
|
|
||||||
|
• In game 1, the game could have been played with as few as 4 red, 2 green, and 6 blue cubes. If any color had even one
|
||||||
|
fewer cube, the game would have been impossible.
|
||||||
|
• Game 2 could have been played with a minimum of 1 red, 3 green, and 4 blue cubes.
|
||||||
|
•
|
||||||
|
• Game 3 must have been played with at least 20 red, 13 green, and 6 blue cubes.
|
||||||
|
• Game 4 required at least 14 red, 3 green, and 15 blue cubes.
|
||||||
|
• Game 5 needed no fewer than 6 red, 3 green, and 2 blue cubes in the bag.
|
||||||
|
|
||||||
|
The power of a set of cubes is equal to the numbers of red, green, and blue cubes multiplied together. The power of the
|
||||||
|
minimum set of cubes in game 1 is 48. In games 2-5 it was 12, 1560, 630, and 36, respectively. Adding up these five powers
|
||||||
|
produces the sum 2286.
|
||||||
|
|
||||||
|
For each game, find the minimum set of cubes that must have been present. What is the sum of the power of these sets?
|
||||||
|
|
||||||
|
Your puzzle answer was 56580.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, you should return to your Advent calendar and try another puzzle.
|
||||||
|
|
||||||
|
If you still want to see it, you can get your puzzle input.
|
||||||
|
|
||||||
|
You can also [Shareon Twitter Mastodon] this puzzle.
|
||||||
|
|
||||||
|
References
|
||||||
|
|
||||||
|
Visible links
|
||||||
|
. https://adventofcode.com/
|
||||||
|
. https://adventofcode.com/2023/about
|
||||||
|
. https://adventofcode.com/2023/events
|
||||||
|
. https://teespring.com/stores/advent-of-code
|
||||||
|
. https://adventofcode.com/2023/settings
|
||||||
|
. https://adventofcode.com/2023/auth/logout
|
||||||
|
. Advent of Code Supporter
|
||||||
|
https://adventofcode.com/2023/support
|
||||||
|
. https://adventofcode.com/2023
|
||||||
|
. https://adventofcode.com/2023
|
||||||
|
. https://adventofcode.com/2023/support
|
||||||
|
. https://adventofcode.com/2023/sponsors
|
||||||
|
. https://adventofcode.com/2023/leaderboard
|
||||||
|
. https://adventofcode.com/2023/stats
|
||||||
|
. https://adventofcode.com/2023/sponsors
|
||||||
|
. https://adventofcode.com/2023
|
||||||
|
. https://adventofcode.com/2023/day/2/input
|
5
2023/day02/testinput
Normal file
5
2023/day02/testinput
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||||
|
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||||
|
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||||
|
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||||
|
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
Loading…
Reference in New Issue
Block a user