# Day 2 - Discoded/adventofcode GitHub Wiki

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?

#### Input:

```
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
```

#### Output:

```
Game 1: possible
Game 2: possible
Game 3: NOT possible
Game 4: NOT possible
Game 5: possible
```

Final answer: **8** (sum of game IDs that were possible (1+2+5=8))

#### Solution:

```
MAX_RED_NUMBER = 12
MAX_GREEN_NUMBER = 13
MAX_BLUE_NUMBER = 14
For each line
store game_id
Split: string by "n color",
For each color:
Check color:
if max_color_number < current_number:
game_is_not_possible_ = true
if game_is_not_possible:
return
else:
game_id_sum += game_id
```

### Day 2 Part 2

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?

#### Input:

```
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
```

#### Output:

```
Game 1: 4*2*6 = 48
Game 2: 1*3*4 = 12
Game 3: 20*13*6 = 1560
Game 4: 14*3*2 = 630
Game 5: 6*3*2 = 36
```

Final answer: **2286** (Sum of the powers of each min color in each line(48+12+1560+630+36))

#### Solution:

```
For each line
store game_id
Split: string by "n color",
For each color:
Check color:
if red:
if min_red < current_number:
min_red = current_number
elif green:
if min_green < current_number:
min_green = current_number
// blue
else:
if min_blue < current_number:
min_blue = current_number
if max_color_number < current_number:
game_is_not_possible_ = true
if game_is_not_possible:
return
else:
game_id_sum += game_id
```