19 lines
576 B
Python
19 lines
576 B
Python
#!/usr/bin/env python3
|
|
import numpy as np
|
|
|
|
lines = (x.strip() for x in open("input.txt"))
|
|
positions = set()
|
|
rope = [np.array((0, 0)) for _ in range(10)]
|
|
dirs = {d: p for d, p in zip("UDLR", ((1, 0), (-1, 0), (0, -1), (0, 1)))}
|
|
|
|
for line in lines:
|
|
d, n = dirs[line[0]], int(line[2:])
|
|
for _ in range(n):
|
|
rope[0] += d
|
|
for i in range(1, len(rope)):
|
|
diff = rope[i-1] - rope[i]
|
|
rope[i] += np.sign(diff) if sum(np.abs(diff)) > 2 else np.sign(diff - np.sign(diff))
|
|
positions.add(tuple(rope[len(rope)-1]))
|
|
|
|
print(len(positions))
|