From b1928afa6cb9b729159a275070f4374ec019e098 Mon Sep 17 00:00:00 2001 From: Mika Suhonen Date: Fri, 9 Dec 2022 17:22:42 +0200 Subject: [PATCH] day 9 part 1 --- 09/i.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 09/i.py diff --git a/09/i.py b/09/i.py new file mode 100644 index 0000000..c19b98b --- /dev/null +++ b/09/i.py @@ -0,0 +1,58 @@ +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)))