26 lines
634 B
Python
26 lines
634 B
Python
#!/usr/bin/env python3
|
|
import numpy as np
|
|
|
|
lines = (x.strip() for x in open("input.txt"))
|
|
positions = set()
|
|
LEN = 2
|
|
rope = [np.array((0, 0)) for i in range(LEN)]
|
|
dirs = {
|
|
"U": np.array((1, 0)),
|
|
"D": np.array((-1, 0)),
|
|
"L": np.array((0, -1)),
|
|
"R": np.array((0, 1)),
|
|
}
|
|
|
|
for line in lines:
|
|
d, i = line.split(" ")
|
|
d, i = dirs[d], int(i)
|
|
for _ in range(i):
|
|
rope[0] += d
|
|
for p in range(1, 2):
|
|
diff = rope[p-1]-rope[p]
|
|
rope[p] += 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))
|