From 9c8d9cbe386d43f15f8f3807513e610efc63916e Mon Sep 17 00:00:00 2001 From: james Date: Sat, 2 Dec 2023 18:52:14 +1100 Subject: [PATCH] #33: Documentation updates --- docs/_posts/2023-12-02-advent-of-code-2023-day2.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/_posts/2023-12-02-advent-of-code-2023-day2.md b/docs/_posts/2023-12-02-advent-of-code-2023-day2.md index 041be23..0df3d08 100644 --- a/docs/_posts/2023-12-02-advent-of-code-2023-day2.md +++ b/docs/_posts/2023-12-02-advent-of-code-2023-day2.md @@ -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