2022-12-06 - Tuning Trouble
(original .ipynb)
Day 6 puzzle input is a sequence of characters (mine is here). Part 1 involves finding the location in the stream after the first sequence of four characters that where none repeat. Part 2 is the same but for fourteen characters.
puzzle_input_str = open("./puzzle_input/day6.txt").read() def part_one(input_str, marker_length=4): buffer = [] for i, c in enumerate(input_str): if len(buffer) == marker_length: buffer.pop(0) buffer.append(c) if len(set(buffer)) == marker_length: return 1 + i return -1 assert 5 == part_one("bvwbjplbgvbhsrlpgdmjqwftvncz") assert 6 == part_one("nppdvjthqldpwncqszvftbrmjlhg") assert 10 == part_one("nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg") assert 11 == part_one("zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw") print("part one:", part_one(puzzle_input_str))
part one: 1833
def part_two(input_str): return part_one(input_str, 14) assert 19 == part_two("mjqjpqmgbljsphdztnvjfqwrcgsmlb") assert 23 == part_two("bvwbjplbgvbhsrlpgdmjqwftvncz") assert 23 == part_two("nppdvjthqldpwncqszvftbrmjlhg") assert 29 == part_two("nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg") assert 26 == part_two("zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw") print("part two:", part_two(puzzle_input_str))
part two: 3425