Created
May 8, 2022 17:22
-
-
Save Mu-adventofcode/88ebda9ee235e214919bd972ae3a9282 to your computer and use it in GitHub Desktop.
Advent of Code 2021 day 14 part 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
My solution for Advent of Code 2021 day 14 part 1. | |
""" | |
import re | |
from collections import Counter | |
with open("input_14.txt") as f: | |
polym = list(f.readline().strip()) | |
rules = { | |
tuple(pair): insert | |
for pair, insert in re.findall(r"(..) -> (.)", f.read()) | |
} | |
for _ in range(10): | |
nextgen = [] | |
for pair in zip(polym[:], polym[1:]): | |
nextgen.append(pair[0]) | |
nextgen.append(rules[pair]) | |
nextgen.append(polym[-1]) | |
polym = nextgen | |
c = Counter(polym).most_common() | |
print(c[0][1] - c[-1][1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment