Module day08

Source
Expand description

Β§Matchsticks

While regular expressions may feel like a natural choice, it’s much faster and easier to simply treat the input as a single stream of raw ASCII u8 bytes without splitting line by line.

For part one we skip over the first quote of each line. The last quote on each line increases the difference by two since every line is enclosed with two quotes. If we encounter a hexadecimal escape then four characters become one so the difference increases by three. The sequences \\ and \" both increase the difference by one.

Part two is even more straightforward. Quotes and backslashes need to be escaped so increase the difference by one. Each newline increases by the difference by two.

ConstantsΒ§

ESCAPE πŸ”’
NEWLINE πŸ”’
QUOTE πŸ”’
SLASH πŸ”’

FunctionsΒ§

parse
part1
part2