Advent of Code 2023 - Day 15Lens Library
| Problem statement | Source code | Tags: Data structures
Part 1
This is like Java string hashing, except that the base is 17 instead of 31, and the modulus is instead of (since in part 2 we only have 256 bins). It's kind of fun because I didn't know how to get the ASCII code for a character; turned out you have to use charToRaw and then as.integer.
Part 2
It's just a really standard hashmap; absolutely nothing to see here. In fact it's simpler than real hashmaps because there's no rehashing. I faithfully implemented the spec, using a list of 256 lists.
Now I can get the powers: