When I saw the problem for Day 6, my first thought was this is probably the day I drop out. I thought I would probably need some kind of advanced spatial search/nearest-neighbor algorithm in order to get the job done, and began googling about for such a thing.
After skimming a couple of whitepapers I took a closer look at the problem and realized I misjudged how complicated it really was. It wasn’t actually going to be that hard.
For one thing, the distances are simple Manhattan distance which are extremely easy to compute.
For another, examining the inputs revealed that we weren’t dealing with a too-huge problem space:
> (define input (map inputline->pair (file->lines "day06-input.txt")))
> (define grid-size (apply max (first (sort input > #:key (curry apply max)))))
> (length input)
50
> grid-size
358
So, fifty points on a 358⨉358 grid. Small-enough that a brute-force solution is probably still going to be fast enough.
So that’s what I tried. And I was right. On to Day 7!