commit a6412e56e85d2bd5343b60fc7d431351c52c2fce from: Lukas Henkel date: Wed Dec 06 05:16:36 2023 UTC Day 6 task 1 commit - df1d03bd1110063b94c895095dd5b9ea889c728a commit + a6412e56e85d2bd5343b60fc7d431351c52c2fce blob - /dev/null blob + 65a261bad7848f9938942188edf76f8b85defaba (mode 644) --- /dev/null +++ input/6.txt @@ -0,0 +1,2 @@ +Time: 47 98 66 98 +Distance: 400 1213 1011 1540 blob - 416178157954497195acf6f38ea5892d0e72d75c blob + e5852cef043cf3746973cdf3f30f383c1c879386 --- src/day-5.lisp +++ src/day-5.lisp @@ -3,15 +3,6 @@ (:export #:day-5)) (in-package #:aoc/day-5) -(defun read-number-list (string &key (start 0)) - (loop for i from start below (length string) - collect (multiple-value-bind (number end) - (parse-integer string - :start i - :junk-allowed t) - (setf i end) - number))) - (defun parse-seeds (input) (let ((line (prog1 (read-line input) blob - /dev/null blob + 48265959d9262090a812590aeb19cda368b8bd8d (mode 644) --- /dev/null +++ src/day-6.lisp @@ -0,0 +1,20 @@ +(defpackage #:aoc/day-6 + (:use #:cl #:aoc/utils) + (:export #:day-6)) +(in-package #:aoc/day-6) + +(defun day-6 (input) + (let* ((line (read-line input)) + (times (read-number-list line :start (1+ (position #\: line)))) + (line (read-line input)) + (distances (read-number-list line :start (1+ (position #\: line))))) + (loop with task-1 = nil + for time in times + for distance in distances + do (push (loop for speed from 1 below time + for remaining-time = (- time speed) + for travelled = (* speed remaining-time) + when (> travelled distance) + sum 1 fixnum) + task-1) + finally (return (apply #'* task-1))))) blob - 235bb19906e235945c11e4da98f9c8b1ba9c22cc blob + 56b3ca8cc742f7c814b1e309330b436f4dd1bb5e --- src/utils.lisp +++ src/utils.lisp @@ -16,7 +16,8 @@ #:point-x #:point-y #:point-neighbours - #:do-map-neighbours)) + #:do-map-neighbours + #:read-number-list)) (in-package #:aoc/utils) (defun normalize-type (type) @@ -160,3 +161,12 @@ (push bb? checks)) checks)) ,@body))))))) + +(defun read-number-list (string &key (start 0)) + (loop for i from start below (length string) + collect (multiple-value-bind (number end) + (parse-integer string + :start i + :junk-allowed t) + (setf i end) + number))) blob - /dev/null blob + 58713c726981e6eab122e1150c00efc7f07014db (mode 644) --- /dev/null +++ t/day-6.lisp @@ -0,0 +1,10 @@ +(defpackage #:aoc-test/day-6 + (:use #:cl #:lisp-unit2)) +(in-package #:aoc-test/day-6) + +(define-test test-day-6 + () + (multiple-value-bind (task-1) + (aoc:run-day 6 "Time: 7 15 30 +Distance: 9 40 200") + (assert= 288 task-1)))