aoc2025

Advent of Code solutions for 2025 in Common Lisp
Log | Files | Refs | README

commit 0dfc884264f32af054892d3c606cb26e682c633e
parent 6513fd0b73342766cf82f9ad98942928cee08fbc
Author: Martin Ashby <martin@ashbysoft.com>
Date:   Thu, 11 Dec 2025 20:52:15 +0000

Day 2 part 1

Diffstat:
A02.input | 1+
A02.lisp | 31+++++++++++++++++++++++++++++++
A02.sample.input | 2++
3 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/02.input b/02.input @@ -0,0 +1 @@ +61-71,12004923-12218173,907895-1086340,61083-74975,7676687127-7676868552,3328-4003,48-59,3826934-3859467,178-235,75491066-75643554,92-115,1487-1860,483139-586979,553489051-553589200,645895-722188,47720238-47818286,152157-192571,9797877401-9798014942,9326-11828,879837-904029,4347588-4499393,17-30,1-16,109218-145341,45794-60133,491-643,2155-2882,7576546102-7576769724,4104-5014,34-46,67594702-67751934,8541532888-8541668837,72-87,346340-480731,3358258808-3358456067,78265-98021,7969-9161,19293-27371,5143721-5316417,5641-7190,28793-36935,3232255123-3232366239,706-847,204915-242531,851-1135,790317-858666 diff --git a/02.lisp b/02.lisp @@ -0,0 +1,30 @@ +(require "asdf") + +(defun day2-part1 (input-file) + (let* ((s (uiop:read-file-string input-file)) + (u (uiop:split-string s :separator ",")) + (tot 0)) + (dolist (v u) + (let* ((w (uiop:split-string v :separator "-")) + (x (parse-integer (first w))) + (y (parse-integer (second w))) + (z (sum-invalids-in-range x y))) + (setf tot (+ tot z)) )) + tot)) + +; I tried to be clever and step through just invalid numbers, but it's quite fiddly handling all the edge cases +; let's see if the naive thing is fast enough +(defun sum-invalids-in-range (start end) + (do ((x start (1+ x)) + (tot 0)) + ((> x end) tot) + (if (is-invalid x) + (setf tot (+ tot x))))) + +(defun is-invalid (x) + (let* ((y (write-to-string x)) + (l (length y)) + (m (floor l 2)) + (n1 (subseq y 0 m)) + (n2 (subseq y m))) + (equal n1 n2))) +\ No newline at end of file diff --git a/02.sample.input b/02.sample.input @@ -0,0 +1 @@ +11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124 +\ No newline at end of file