Module aoc::year2021::day08

source ·
Expand description

Listing each digit and the number of segments that are lit when that digit is displayed:

0123456789
6255456376

shows that 3 digits share 5 segments and another 3 share 6 segments so we don’t have enough information just yet. Listing the total occurences of each segment summing across all 10 digits:

abcdefg
8687497

shows that 2 segments share 7 occurences and 2 share 8 occurences so this is still not quite enough information. However if we combine these 2 tables by summing the segment occurences for each digit, for example 1 has segments c and f for a total of 17, then the table looks like:

0123456789
42173439303741254945

Now each digit can be uniquely identified. Our algorithm is as follows:

  • Calculate the occurences of each scrambled segment letter before the | symbol. Since the cardinality of the set is fixed, we can use an array instead of a HashMap for speed.
  • Add the occurences of each scrambled segment for each digit after the | symbol, then lookup the total and map directly to the unscrambled digit.

Functions§

Type Aliases§