cheated p2
This commit is contained in:
75
09/i.py
75
09/i.py
@@ -5,54 +5,43 @@ input = open(os.path.dirname(__file__) +
|
|||||||
"/input.txt", "r").readlines()
|
"/input.txt", "r").readlines()
|
||||||
|
|
||||||
|
|
||||||
def distance(i: int, j: int):
|
def dir(d):
|
||||||
return math.dist([i], [j])
|
match d:
|
||||||
|
case 'R': return (1, 0)
|
||||||
|
case 'L': return (-1, 0)
|
||||||
|
case 'U': return (0, 1)
|
||||||
|
case 'D': return (0, -1)
|
||||||
|
|
||||||
|
|
||||||
|
max = 10
|
||||||
|
|
||||||
tails = []
|
tails = []
|
||||||
tail = [0, 0]
|
rope = [(0, 0) for i in range(max)]
|
||||||
head = [0, 0] # x, y
|
|
||||||
for l in input:
|
for l in input:
|
||||||
moves = l.split()
|
moves = l.split()
|
||||||
print(moves)
|
m = dir(moves[0])
|
||||||
for steps in range(int(moves[1])):
|
for steps in range(int(moves[1])):
|
||||||
|
rope[0] = [rope[0][0]+m[0], rope[0][1]+m[1]]
|
||||||
|
for r in range(max-1):
|
||||||
|
k, kn = rope[r:r+2]
|
||||||
|
dx, dy = k[0]-kn[0], k[1] - kn[1]
|
||||||
|
dist = abs(dx) + abs(dy)
|
||||||
|
if dist == 2:
|
||||||
|
if k[0] == kn[0]:
|
||||||
|
rope[r+1] = (rope[r+1][0], rope[r+1][1]+dy//2)
|
||||||
|
elif k[1] == kn[1]:
|
||||||
|
rope[r+1] = (rope[r+1][0]+dx//2, rope[r+1][1])
|
||||||
|
elif dist == 3:
|
||||||
|
if abs(dx) == 2:
|
||||||
|
rope[r+1] = (rope[r+1][0]+dx//2, rope[r][1])
|
||||||
|
elif abs(dy) == 2:
|
||||||
|
rope[r+1] = (rope[r][0], rope[r+1][1]+dy//2)
|
||||||
|
elif dist == 4:
|
||||||
|
rope[r+1] = (rope[r+1][0]+dx//2, rope[r+1][1]+dy//2)
|
||||||
|
tails.append(rope[-1])
|
||||||
|
|
||||||
match moves[0]:
|
l = []
|
||||||
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:
|
for i in tails:
|
||||||
list.append(str(i[0])+","+str(i[1]))
|
l.append(str(i[0])+","+str(i[1]))
|
||||||
|
print(len(set(l)))
|
||||||
print(len(set(list)))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user