Skip to content

Commit

Permalink
#33: Documentation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jaccomoc committed Dec 2, 2023
1 parent 65dbf9c commit 9c8d9cb
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions docs/_posts/2023-12-02-advent-of-code-2023-day2.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ Each game, therefore, gets its own minimum bag with a count per colour.
Then we multiply these counts together for each game and sum these products for the final solution:

```groovy
stream(nextLine).map{ /Game (\d+): (.*)$/n;
$2.split(/;/)
.flatMap{ it.split(/,/).map{ /(\d+) (.*)/n; [$2,$1] } }
.sort() as Map }
.map{ it.reduce(1){ prod,entry -> prod * entry[1] } }
.sum()
stream(nextLine).map{ it.split(/: /)[1].split(/;/)
.flatMap{ it.split(/,/).map{ /(\d+) (.*)/n; [$2,$1] } }.sort() as Map }
.map{ it.reduce(1){ prod,entry -> prod * entry[1] } }.sum()
```

The only trick here is to generate a simple list of [colour, count] for each game and then sort these so that
Expand Down

0 comments on commit 9c8d9cb

Please sign in to comment.