Skip to content
advent of code 2015

day 10

elves look, elves say

approach

this one is unfinished as committed. the idea is all there: step run-length encodes the string with itertools.groupby, and steps applies a function k times.

but sol.py is left in the middle of a debugging session. it compares step against two other look-and-say implementations pasted into the file, the lines that print the two answers are commented out, and one of the debug prints is missing a closing parenthesis, so the file doesn't run. sol2.py is a fragment that calls one of those functions without defining it.

the trick

look-and-say is run-length encoding, and groupby already yields the runs.

python
def step(s):
    res = []
    for k, g in groupby(s):
        l = list(g)
        res.append(f"{len(l)}{k}")
    return "".join(res)