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

day16_part1.py (1069B)


      1 #!/usr/bin/env python
      2 """Advent of Code 2021, day 16 (part 1): Packet Decoder
      3 Parsing packets using the Buoyancy Interchange Transmission System (BITS)"""
      4 
      5 # Okay, I finally made some custom classes to solve an AoC problem. I've heard
      6 # stories about the intcode computer stuff, and I figure this stuff might come
      7 # in handy in a future puzzle, but I didn't exactly _over_ engineer anything
      8 # either.
      9 
     10 from day16_classes import BitReader, Packet
     11 from utils import get_puzzle_input
     12 
     13 def solve_puzzle(input_string: str) -> int:
     14     """Return the numeric solution to the puzzle"""
     15     return Packet(BitReader(input_string)).version_sum()
     16 
     17 def main() -> None:
     18     """Run when the file is called as a script"""
     19     assert solve_puzzle("8A004A801A8002F478") == 16
     20     assert solve_puzzle("620080001611562C8802118E34") == 12
     21     assert solve_puzzle("C0015000016115A2E0802F182340") == 23
     22     assert solve_puzzle("A0016C880162017C3686B18A3D4780") == 31
     23 
     24     print("Total packet version sum:",
     25           solve_puzzle(get_puzzle_input(16)))
     26 
     27 if __name__ == "__main__":
     28     main()