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_part2.py (1161B)


      1 #!/usr/bin/env python
      2 """Advent of Code 2021, day 16 (part 2): Packet Decoder
      3 Processing packets using the Buoyancy Interchange Transmission System (BITS)"""
      4 
      5 # Not only am I defining classes for the first time, I'm also allowing myself
      6 # to change part 1 code in order to complete part 2 (I had a feeling I'd be
      7 # adding features to my Packet class)
      8 
      9 from day16_classes import BitReader, Packet
     10 from utils import get_puzzle_input
     11 
     12 def solve_puzzle(input_string: str) -> int:
     13     """Return the numeric solution to the puzzle"""
     14     return Packet(BitReader(input_string)).operation_result()
     15 
     16 def main() -> None:
     17     """Run when the file is called as a script"""
     18     assert solve_puzzle("C200B40A82") == 3
     19     assert solve_puzzle("04005AC33890") == 54
     20     assert solve_puzzle("880086C3E88112") == 7
     21     assert solve_puzzle("CE00C43D881120") == 9
     22     assert solve_puzzle("D8005AC2A8F0") == 1
     23     assert solve_puzzle("F600BC2D8F") == 0
     24     assert solve_puzzle("9C005AC2F8F0") == 0
     25     assert solve_puzzle("9C0141080250320F1802104A08") == 1
     26 
     27     print("Packet expression result:",
     28           solve_puzzle(get_puzzle_input(16)))
     29 
     30 if __name__ == "__main__":
     31     main()