Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

21 lines
610B

  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]))