You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
from collections import defaultdict
|
|
|
|
with open("input") as f:
|
|
start_number = f.readline().strip()
|
|
|
|
print("Start:", start_number, "length:", len(start_number))
|
|
|
|
ATOM_TO_NUMBER = dict()
|
|
NUMBER_TO_ATOM = dict()
|
|
DECAY = dict()
|
|
|
|
# From https://web.archive.org/web/20061224154744/http://www.uam.es/personal_pdi/ciencias/omartin/Biochem.PDF
|
|
with open("atoms") as f:
|
|
for line in f.readlines():
|
|
columns = line.strip().split(" ")
|
|
[_, atom, number] = columns[:3]
|
|
NUMBER_TO_ATOM[number] = atom
|
|
ATOM_TO_NUMBER[atom] = number
|
|
DECAY[atom] = columns[3:]
|
|
|
|
start_atom = NUMBER_TO_ATOM[start_number]
|
|
|
|
print("Starting with atom:", start_atom)
|
|
|
|
ATOM_COUNT = defaultdict(int)
|
|
ATOM_COUNT[start_atom] = 1
|
|
|
|
for i in range(50):
|
|
NEXT_ATOM_COUNT = defaultdict(int)
|
|
for atom, count in ATOM_COUNT.items():
|
|
for new_atom in DECAY[atom]:
|
|
NEXT_ATOM_COUNT[new_atom] += count
|
|
ATOM_COUNT = NEXT_ATOM_COUNT
|
|
|
|
length = 0
|
|
for atom, count in ATOM_COUNT.items():
|
|
length += len(ATOM_TO_NUMBER[atom]) * count
|
|
|
|
print("Round", i + 1, "len:", length)
|
|
|
|
print(length)
|