advent_of_code_2021

My attempts to work through the 2021 Advent of Code problems.
git clone https://git.eamoncaddigan.net/advent_of_code_2021.git
Log | Files | Refs | README | LICENSE

commit 3078459e2f86c11c6446a3470f9cb7af42eea255
parent 7577a99b6a66f5a4fe7338109efa4d2bc62d7f92
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date:   Tue, 14 Dec 2021 14:38:26 -0500

Solution to day 14, part 2

Diffstat:
Aday14_part2.py | 28++++++++++++++++++++++++++++
1 file changed, 28 insertions(+), 0 deletions(-)

diff --git a/day14_part2.py b/day14_part2.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +"""Advent of Code 2021, day 14 (part 2): Extended Polymerization +Perform 'pair insertions' on a 'polymer' string even more times""" + +# Ah-ha, it _is_ lanternfish all over again; I'm glad I went with a compact +# representation. I was worried that I'd need to find 4-grams or something +# which would have required a complete retooling, and I'm glad I didn't program +# for it. + +from day14_part1 import (EXAMPLE_INPUT, + parse_input, + apply_insertions) +from utils import get_puzzle_input + +def solve_puzzle(input_string: str) -> int: + """Return the numeric solution to the puzzle""" + element_count = apply_insertions(*(parse_input(input_string) + (40,))) + return int(element_count.max() - element_count.min()) + +def main() -> None: + """Run when the file is called as a script""" + assert solve_puzzle(EXAMPLE_INPUT) == 2188189693529 + print("Difference between most and least common elements", + "(after many more insertions):", + solve_puzzle(get_puzzle_input(14))) + +if __name__ == "__main__": + main()