2015-12-10 - Elves Look, Elves Say
(original .ipynb)
Puzzle input is a string of integer digits. Part one involves applying some rules of a game to expand the string of digits 40 times. Part two is the same but for 50 times.
puzzle_input_str = open("./puzzle_input/day10.txt").read() def step(digits): prev = digits[0] count = 1 for d in digits[1:]: if prev == d: count += 1 else: yield count yield prev prev = d count = 1 yield count yield prev def expand(digits, count=40): while count > 0: digits = list(step(digits)) count -= 1 return digits def part_one(input_str, count=40): digits = expand([int(c) for c in input_str], count) return len(digits) def stringify(l): return "".join(str(d) for d in l) assert "11" == stringify(expand("1", 1)) assert "21" == stringify(expand("11", 1)) assert "1211" == stringify(expand("21", 1)) assert "111221" == stringify(expand("1211", 1)) assert "312211" == stringify(expand("111221", 1)) print("part one:", part_one(puzzle_input_str))
part one: 252594
def part_two(input_str): return part_one(input_str, 50) print("part two:", part_two(puzzle_input_str))
part two: 3579328