56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
import fileinput
|
|
|
|
tx, ty, hx, hy = 0, 0, 0, 0
|
|
|
|
tail_positions = set()
|
|
|
|
for line in fileinput.input():
|
|
dir_, steps = line.split()
|
|
|
|
dx, dy = 0, 0
|
|
match dir_:
|
|
case "U":
|
|
dx, dy = 0, 1
|
|
case "D":
|
|
dx, dy = 0, -1
|
|
case "L":
|
|
dx, dy = -1, 0
|
|
case "R":
|
|
dx, dy = 1, 0
|
|
case _:
|
|
assert False
|
|
|
|
for _ in range(int(steps)):
|
|
hx_, hy_ = hx, hy
|
|
hx += dx
|
|
hy += dy
|
|
if abs(tx - hx) > 1 or abs(ty - hy) > 1:
|
|
tx = hx_
|
|
ty = hy_
|
|
# for y in range(6, -1, -1):
|
|
# for x in range(6):
|
|
# if (x, y) == (hx, hy):
|
|
# print("H", end="")
|
|
# elif (x, y) == (tx, ty):
|
|
# print("T", end="")
|
|
# elif (x, y) == (0, 0):
|
|
# print("s", end="")
|
|
# else:
|
|
# print(".", end="")
|
|
# print()
|
|
# print()
|
|
tail_positions.add((tx, ty))
|
|
print("========")
|
|
|
|
print(len(tail_positions))
|
|
|
|
for y in range(10, -1, -1):
|
|
for x in range(20):
|
|
if (x, y) == (0, 0):
|
|
print("s", end="")
|
|
elif (x, y) in tail_positions:
|
|
print("#", end="")
|
|
else:
|
|
print(".", end="")
|
|
print()
|