- https://adventofcode.com/2021
- https://2021-aoc-templates.util.repl.co/
- https://github.com/Bogdanp/awesome-advent-of-code
The notes below cover non-Clojure implementations of solutions.
Day 1: Sonar Sweep
The base implementation is an iteration holding on to the current depth with an optional previous depth.
Other related implementations use partitioning and sliding window approaches.
Reasonable windowing implementation with count and a predicate rule.
input.windowed(size: 2).count { (a, b) -> a < b }
- Ruby zip
Day 2: Dive!
Structural Pattern Matching used in a number of implementations.
- TypeScript
Most implementations just looked at a basic case lookup but looked at a position update rather than the conditional blocks.
Alternatively look at move[direction](increment)(position)
:
type Point = {
x: number;
y: number;
};
const move = {
forward: (inc: number) => (p: Point) => {
p.x += inc;
return p;
},
up: (inc: number) => (p: Point) => {
p.y -= inc;
return p;
},
down: (inc: number) => (p: Point) => {
p.y += inc;
return p;
},
};