
I got got :smile:. First mistake: eagerly +1’ing neighbors. Second big mistake: not checking for double-flashers in the chain reaction …. after two steps most of the test board was 0!

Nothing fancy here. Immutable hash mapping (cons x y) -> (cons energy flashed?), which I repeatedly step by (1) bumping all energies, (2) flashing once until a fixpoint is reached, (3) reset those that flashed. https://github.com/benknoble/advent2021/blob/main/day11/solution.rkt

I like this: (~> (dx dy) (all zero?))

Multi values again :) I think the single value equivalent is like (~>> (list dx dy) (andmap zero?))

I use the threading form a lot, but it’s technically the same as ((flow (all zero?)) dx dy)

My list based, functional version of <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2021/solutions/day11/day11.rkt|Day 11>

And here is a <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2021/solutions/day11/day11-min.rkt|minimal version> that stops short of some imaginary “too far” line, although YMMV :)

I think I’d have written this with map, since the for/list isn’t do anything extra and the mapping function is just increment-octo
https://github.com/lojic/LearningRacket/blob/8bb865d18d978f105753dd7e0ae8e8e3d4f8e9c6/advent-of-code-2021/solutions/day11/day11.rkt#L29\|https://github.com/lojic/LearningRacket/blob/8bb865d18d978f105753dd7e0ae8e8e3d4f8e9c6/advent-of-code-2021/solutions/day11/day11.rkt#L29

Ah - good catch. Thanks!

I originally had maps for most (all?) of the for/list
, but while I prefer map
aesthetically, I think most non-lispers (and maybe lispers also) find for/list
more readable. My mistake was probably in having a lambda in my original map vs. just increment-octo

Created <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2021/solutions/day11/day11-alt.rkt|an alternate version> that uses a tuple of number of flashes and list of octopi for the state which allowed me to simplify the parts to: (define (part1 s)
(flashes (iterate step s 100)))
(define (part2 s)
(repeat-until #:action (λ (s) (step (clear s)))
#:stop? (λ (s) (= (flashes s) 100))
s))
but I’m not sure I like it better since the rest of the code is more complicated. Advent of Code puzzles aren’t really large enough in scope to flush out design alternatives properly, but it’s still fun to experiment.

@steven263 has joined the channel

Day 12 spoilers

Spent more time cleaning the code and making it a bit more performant than I did solving it. I think this is a good one for discussing algorithms for performance (at least part 2).
https://github.com/massung/advent2021/blob/main/day12/day12.lisp

First iteration took 0.22s to run. Using a hash for the graph instead of a list took it to 0.18s. Converting it to a list of symbols instead of a hash table took it down to 0.07s, but definitely increased the complexity a bit.