Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

30 linhas
782B

  1. def pythonize(string):
  2. op, out = (
  3. re.sub(r'([a-z]+)', r'\1_', string)
  4. .replace('AND', '&')
  5. .replace('OR', '|')
  6. .replace('NOT ', '~')
  7. .replace('RSHIFT', '>>')
  8. .replace('LSHIFT', '<<')
  9. ).split(' -> ')
  10. return f'{out} = {op}'
  11. def process(instructions, registers={}):
  12. while instructions:
  13. curr, *instructions = instructions
  14. out = curr.split()[0]
  15. if out in registers:
  16. continue
  17. try:
  18. exec(curr, None, registers)
  19. except NameError:
  20. instructions.append(curr)
  21. return registers
  22. inp = [pythonize(string) for string in data_file.read_text().splitlines()]
  23. found = process(inp.copy())
  24. ans1 = found['a_']
  25. ans2 = process(inp.copy(), {'b_': ans1})['a_']