Skip to main content

Module day03

Module day03 

Source
Expand description

§Binary Diagnostic

Part one collects 12 frequency counters, one for each digit lane. Each line of input increments the corresponding counters for each 1. The number of 0 in the lane can be recovered by subtraction, making it easy to construct both the gamma and epsilon rate.

Part two constructs a binary tree, stored as an array. Using an array of 2*4096 bins is enough to treat each of the 1000 unique inputs as a leaf in the second half of the array, and then each node in the first half is computed as the sum of its two children from the right half. The array can be built in linear time, at which point finding the oxygen generator rating and CO2 scrubber rating are each a binary search in the tree.

Structs§

Input

Functions§

parse
part1
part2