advent-of-code-2023

My solutions to AoC 2023
git clone git://git.entf.net/advent-of-code-2023
Log | Files | Refs

commit 26569d70e0e3c2a53f2a975ca9c6d741617d16d5
parent 507576ca9b1e463b8f220568d138b5547e530393
Author: Lukas Henkel <lh@entf.net>
Date:   Sat,  2 Dec 2023 06:39:25 +0100

Day 2 task 2

Diffstat:
Msrc/day-2.lisp | 9++++++++-
Mt/day-2.lisp | 8+++++---
2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/day-2.lisp b/src/day-2.lisp @@ -28,10 +28,17 @@ (or (null blue) (<= blue 14))))) +(defun game-power (sets) + (apply #'* + (mapcar (lambda (color) + (apply #'max (cons 0 (remove nil (mapcar (rcurry #'getf color) sets))))) + (list :red :green :blue)))) + (defun day-2 (input) (loop for line = (read-line input nil) while line for (game sets) = (parse-game-line line) when (game-possible-p sets) sum game into task-1 - finally (return (values task-1)))) + sum (game-power sets) into task-2 + finally (return (values task-1 task-2)))) diff --git a/t/day-2.lisp b/t/day-2.lisp @@ -4,9 +4,11 @@ (define-test test-day-2 () - (assert= 8 - (aoc:run-day 2 "Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green + (multiple-value-bind (task-1 task-2) + (aoc:run-day 2 "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"))) +Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green") + (assert= 8 task-1) + (assert= 2286 task-2)))