Module aoc::year2015::day11

source ยท
Expand description

ยงCorporate Policy

Like the previous day we rely on the special structure of the input to solve more efficiently than the general case.

The key observation is that if there are no straights or pairs in the first 4 digits then the next lowest valid sequence will end in a string of the form aabcc, compressing 2 pairs and a straight into 5 digits.

  • If the current string ends with xxyzz then increment the third digit and wrap around to aabcc.
  • The 5 digit sequence cannot start with any letter from g to o inclusive or it would contain an invalid character somewhere in the sequence.

Functionsยง

  • clean ๐Ÿ”’
    Sanitize the input to make sure it has no invalid characters. We increment the first invalid character found, for example abcixyz becomes abcjaaa.
  • fill ๐Ÿ”’
    Creates a sequence of form aabcc from an arbitrary starting character.
  • next_password ๐Ÿ”’
    Find the next valid 5 digit sequence of form aabcc.

Type Aliasesยง