ben
2021-12-11 14:44:56

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!


ben.knoble
2021-12-11 16:10:10

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


massung
2021-12-11 16:53:30

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


ben.knoble
2021-12-11 16:55:06

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


ben.knoble
2021-12-11 16:55:59

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


badkins
2021-12-11 17:59:09

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


badkins
2021-12-11 18:22:45

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 :)



badkins
2021-12-11 18:26:20

Ah - good catch. Thanks!


badkins
2021-12-11 18:27:30

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


badkins
2021-12-12 01:45:08

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
2021-12-12 01:56:52

@steven263 has joined the channel


massung
2021-12-12 06:01:42

Day 12 spoilers


massung
2021-12-12 06:02:45

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


massung
2021-12-12 07:02:52

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.