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

day06_part2.py (1511B)


      1 #!/usr/bin/env python
      2 """Advent of Code 2021, day 6 (part 2): simulate an exponentially growing
      3 school of lanternfish using an initial list of fish and their ages... for a
      4 longer period than part 1"""
      5 
      6 # I find myself metagaming a little bit: anticipating how part 2 will build
      7 # upon part 1, while trying to make it easy to accommodate in my existing code
      8 # without over-engineering things for functionality that won't become
      9 # necessary. IME, this is what being a programmer (including 'data scientist')
     10 # in the real world is actually like.
     11 #
     12 # In this case, I was imagining something more complicated, like: maybe there
     13 # are a couple different types of fish, or maybe the fish die eventually, or
     14 # maybe the spawn rate depends on the size of the school. But instead we're
     15 # doing something dead simple: running the same solution as before, but for
     16 # longer. I suspect that this is supposed to punish people who
     17 # implemented a list of fish instead of a set of counts.
     18 
     19 from day06_part1 import (convert_input_to_series,
     20                          count_fish_after)
     21 from utils import get_puzzle_input
     22 
     23 def solve_puzzle(input_string):
     24     """Return the numeric solution to the puzzle"""
     25     return count_fish_after(convert_input_to_series(input_string), 256)
     26 
     27 def main():
     28     """Run when the file is called as a script"""
     29     assert solve_puzzle("3,4,3,1,2\n") == 26984457539
     30     print("Number of lanternfish after 256 days:",
     31           solve_puzzle(get_puzzle_input(6)))
     32 
     33 if __name__ == "__main__":
     34     main()