original_docstring: Run opcodes with registers initialised to 0 to identify halt values.
docstring: Run opcodes with registers initialised to 0 to identify halt values.
docstring_tokens: Run opcodes with registers initialised to 0 to identify halt values .
code: def main():
      """Run opcodes with registers initialised to 0 to identify halt values."""
      with open('inputs/day_21.txt') as f:
          lines = [x.strip() for x in f.readlines()]
          start_ip = int(lines[0].split()[1])
          opcodes = []
          for line in lines[1:]:
              split = line.split()
              parsed = (split[0], int(split[1]), int(split[2]), int(split[3]))
              opcodes.append(parsed)
  
          reg_twos = set()
          prev_reg_two = None
          registers = [0, 0, 0, 0, 0, 0]
          position = 0
          while True:
              if position == 28:
                  if not reg_twos:
                      # Answer One
                      print("Register 0 causing quickest halt:", registers[2])
  
                  # Track register 2 values at this potential halting point
                  if registers[2] in reg_twos:
                      # Answer Two
                      print("Register 0 causing slowest halt:", prev_reg_two)
                      break
                  prev_reg_two = registers[2]
                  reg_twos.add(registers[2])
  
              opcode = opcodes[position]
  
              registers[start_ip] = position
  
              function_dispatch(registers, opcode)
  
              position = registers[start_ip] + 1
code_tokens: def main ( ) : with open ( 'inputs/day_21.txt' ) as f : lines = [ x . strip ( ) for x in f . readlines ( ) ] start_ip = int ( lines [ 0 ] . split ( ) [ 1 ] ) opcodes = [ ] for line in lines [ 1 : ] : split = line . split ( ) parsed = ( split [ 0 ] , int ( split [ 1 ] ) , int ( split [ 2 ] ) , int ( split [ 3 ] ) ) opcodes . append ( parsed ) reg_twos = set ( ) prev_reg_two = None registers = [ 0 , 0 , 0 , 0 , 0 , 0 ] position = 0 while True : if position == 28 : if not reg_twos : print ( "Register 0 causing quickest halt:" , registers [ 2 ] ) if registers [ 2 ] in reg_twos : print ( "Register 0 causing slowest halt:" , prev_reg_two ) break prev_reg_two = registers [ 2 ] reg_twos . add ( registers [ 2 ] ) opcode = opcodes [ position ] registers [ start_ip ] = position function_dispatch ( registers , opcode ) position = registers [ start_ip ] + 1
short_docstring: Run opcodes with registers initialised to 0 to identify halt values.
short_docstring_tokens: Run opcodes with registers initialised to 0 to identify halt values .
comment: """Run opcodes with registers initialised to 0 to identify halt values."""$SEP$# Answer One$SEP$# Track register 2 values at this potential halting point$SEP$# Answer Two