59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
import os
|
|
import math
|
|
|
|
input = open(os.path.dirname(__file__) +
|
|
"/input.txt", "r").readlines()
|
|
|
|
|
|
def distance(i: int, j: int):
|
|
return math.dist([i], [j])
|
|
|
|
|
|
tails = []
|
|
tail = [0, 0]
|
|
head = [0, 0] # x, y
|
|
for l in input:
|
|
moves = l.split()
|
|
print(moves)
|
|
for steps in range(int(moves[1])):
|
|
|
|
match moves[0]:
|
|
case 'R':
|
|
print(">")
|
|
head = [head[0]+1, head[1]]
|
|
if distance(head[0], tail[0]) > 1:
|
|
if (tail[1] != head[1]):
|
|
tail[1] = head[1]
|
|
tail[0] += 1
|
|
case 'L':
|
|
print("<")
|
|
head = [head[0]-1, head[1]]
|
|
if distance(tail[0], head[0]) > 1:
|
|
if tail[1] != head[1]:
|
|
tail[1] = head[1]
|
|
tail[0] -= 1
|
|
case 'U':
|
|
print("^")
|
|
head = [head[0], head[1]+1]
|
|
if distance(head[1], tail[1]) > 1:
|
|
if tail[0] != head[0]:
|
|
tail[0] = head[0]
|
|
tail[1] += 1
|
|
case 'D':
|
|
print("v")
|
|
head = [head[0], head[1]-1]
|
|
if distance(tail[1], head[1]) > 1:
|
|
if tail[0] != head[0]:
|
|
tail[0] = head[0]
|
|
tail[1] -= 1
|
|
|
|
print(head)
|
|
print(tail)
|
|
tails.append(tail.copy())
|
|
|
|
list = []
|
|
for i in tails:
|
|
list.append(str(i[0])+","+str(i[1]))
|
|
|
|
print(len(set(list)))
|