Sean McLemon | Advent of Code

Home | Czech | Blog | GitHub | Advent Of Code | Notes


2024-12-19 - Linen Layout

(original .ipynb)
puzzle_input_str = open("./puzzle_input/day19.txt").read()
test_input_str = """r, wr, b, g, bwu, rb, gb, br

brwrr
bggr
gbbr
rrbgbr
ubwu
bwurrg
brgr
bbrgwb"""


def parse_pattern(total_string, pattern, parse_tree):
    if len(pattern) == 0:
        return

    token, rest = pattern[0], pattern[1:]
    if token not in parse_tree:
        subtree = {}
        parse_pattern(total_string + token, rest, subtree)
        parse_tree[token] = subtree
    else:
        parse_pattern(total_string + token)

def parse_patterns(patterns):
    parse_tree = {}
    for pattern in patterns:
        parse_pattern("", pattern, parse_tree)
    return parse_tree

def parse_input(input_str):
    patterns_str, designs_str = input_str.split("\n\n")
    patterns = [pattern for pattern in patterns_str.split(", ")]
    designs = [design for design in designs_str.split("\n")]
    return patterns, designs




def part_one(input_str):
    patterns, designs = parse_input(input_str)
    return 0


assert 0 == part_one(test_input_str)

print("part one:", part_one(puzzle_input_str))
part one: 0