Advent of Code 2018
day 1 in eight languages
This year I used Advent of Code as an excuse to try lots of languages. Day 1 is solved in all eight: Clojure, Crystal, Go, Haskell, Idris, Racket, Ruby and TypeScript. After that I picked whichever felt right for each puzzle, and Haskell and Clojure ended up with the most days. I got through Day 18. Day 15, the goblin battle, took the longest; my first working Crystal version was slow and needed a couple of speedups. A small Ruby script builds the star table in the README from the solutions. My favourite trick is in Racket, where Day 1 part 2 escapes its loop with call/cc:
(define part-2
(call/cc
(λ (return)
(let loop ([rows input] [seen (set)] [ freq 0 ])
(if (empty? rows)
(loop input seen freq)
(let ([freq (+ (car rows) freq)])
(if (set-member? seen freq)
(return freq)
(loop (cdr rows) (set-add seen freq) freq))))))))
Source on GitHub: Jell/advent2018