You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 jaren geleden
1234567891011121314151617181920
  1. def move(diff):
  2. dt = 0
  3. if max(abs(diff.real), abs(diff.imag)) > 1:
  4. dt += diff.real and diff.real / abs(diff.real)
  5. dt += diff.imag and (diff.imag / abs(diff.imag)) * 1j
  6. return dt
  7. moves = dict(zip('LRUD', [-1, 1, -1j, 1j]))
  8. state = {i: 0 for i in range(10)}
  9. history = {i: set() for i in state}
  10. for instruction in open(0).read().splitlines():
  11. k, v = instruction.split()
  12. for step in k * int(v):
  13. for i in state:
  14. state[i] += move(state[i - 1] - state[i]) if i else moves[k]
  15. history[i].add(state[i])
  16. print(len(history[0]))
  17. print(len(history[9]))