Skip to content

Instantly share code, notes, and snippets.

@Mu-adventofcode
Created May 8, 2022 17:22
Show Gist options
  • Save Mu-adventofcode/88ebda9ee235e214919bd972ae3a9282 to your computer and use it in GitHub Desktop.
Save Mu-adventofcode/88ebda9ee235e214919bd972ae3a9282 to your computer and use it in GitHub Desktop.
Advent of Code 2021 day 14 part 1
"""
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