Data Structures
Every game has an id and many [] (sub)sets
(sub)sets is just a map of color to count
Why not struct with colors as keys
Will have to handle each color
Don’t know if there are more colors in bag
Parsing
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
For each line:
- Scan
Id - Split by
:, discard first half - Split by
;, we get subsets- Create map
- Split by
,we get colors and counts - Trim space
- Scan
color,count - Update our map
Part 1
Check all subsets of each game
If each subset is valid, select game Subsets are totally independent
gist : Just loop
Approach 1
Flag to see if game is valid
Correct
Don’t want to deal with flag 💆♂️
Approach 2
Select game, deselect if not valid
Correct
Got to use loop labels
Part 2
Check all subsets of each game
Keep track of max for each game
gist : Just loop
Can reuse earlier declared data structure