Idiomdrottning’s homepage

Advent of Code, 2025

Here is where I’ll post my solutions to Advent of Code using zshbrev. Spoilers ahead, and no promises that I’ll make it through the entire 12 days.

Dec 1st

(define (turn)
  (define-parameters zero 0)
  (fold
   (fn
    (with-result
     (when
         (zero?
          (save
           (modulo
            (+ (string->number
                (strse x "L" "-" "R" "")) y) 100)))
       (zero (add1 (zero))))))
   50
   (read-lines))
  (zero))

Last time I attempted Advent of Code, I got tangled up modifying the step one solutions to handle step two and then I ended up wanting to revisit step one but they were gone. So this year I’m going to try to paste a second copy before modifying and I hope that works out better.

(define (dial acc r d)
  (with (+ d r)
    (when
        (or
         (zero? it)
         (= 100 it)
         (< it 0 d)
         (< d 100 it))
      (acc))
    (modulo it 100)))

(define (dial acc (? (fn (< x -100)) r) d)
  (acc)
  (dial acc (+ r 100) d))

(define (dial acc (? (fn (< 100 x)) r) d)
  (acc)
  (dial acc (- r 100) d))

(define (dial acc (? string? x) y)
 (dial acc (string->number (strse x "L" "-" "R" "")) y))

(define (turnDX)
  (define-parameters zero 0)
  (fold (c dial (fn (zero (add1 (zero))))) 50 (read-lines))
  (zero))

This was one of the hardest bugs I’ve ever had to debug.
I’ve had to write log parsers, differs between different logs from different versions, multiple implementations to check against each other, Emacs highlight-regexp and count-matches and so on. It took me ten tries on the Advent of Code website. I get paranoid that I had mistyped my answer in there.

The line that now says (< it 0 d), originally I had it as (<= it 0 d) but it gave false positives on rotating from zero.

For a while I had it as (and (< it 0) (<= 0 d)) which… doesn’t fix that problem at all. Even after coming up with the fix (< it 0 d), that gives false negatives on rotating exactly one rotation left from zero. But there’s no L100 in the data set? No, but my code before I cleaned it up had:

(dial acc (+ r 100)
      (dial acc -100 d))

where it now says:

(acc)
(dial acc (+ r 100) d)

…leading to lots and lots of zero to zero turns which came with a false positive in some versions and false positives in others.

A complete PEBCAK on my part but the hunt for the bug became a real adventure of trying to sift through clues in logs that were thousands of lines long.