summaryrefslogtreecommitdiffstats
path: root/solutions/py/03-1.py
diff options
context:
space:
mode:
authorGustav Sörnäs <gusso230@student.liu.se>2019-12-04 07:02:31 +0100
committerGustav Sörnäs <gusso230@student.liu.se>2019-12-04 07:02:31 +0100
commit831755fdc6d430bd8781da1897270cf2934bc858 (patch)
treef1d6e5609363f98534a87eb9203a7623fb409371 /solutions/py/03-1.py
downloadaoc-831755fdc6d430bd8781da1897270cf2934bc858.tar.gz
Initial commit
Diffstat (limited to 'solutions/py/03-1.py')
-rw-r--r--solutions/py/03-1.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/solutions/py/03-1.py b/solutions/py/03-1.py
new file mode 100644
index 0000000..dea1c05
--- /dev/null
+++ b/solutions/py/03-1.py
@@ -0,0 +1,41 @@
+import math
+
+
+def intersection(l1, l2):
+ tmp = set(l1)
+ return [value for value in l2 if value in tmp]
+
+def man_dist(point):
+ return abs(point[0]) + abs(point[1])
+
+
+wire1 = []
+wire2 = []
+for wire in (wire1, wire2):
+ x = 0
+ y = 0
+ dx = 0
+ dy = 0
+ for move in input().split(","):
+ if move[0] == "D":
+ dx = 0
+ dy = -1
+ elif move[0] == "U":
+ dx = 0
+ dy = 1
+ elif move[0] == "R":
+ dx = 1
+ dy = 0
+ elif move[0] == "L":
+ dx = -1
+ dy = 0
+ for i in range(int(move[1:])):
+ x += dx
+ y += dy
+ wire.append((x, y))
+points = intersection(wire1, wire2)
+print(len(points))
+dist = man_dist(points[0])
+for point in points[1:]:
+ dist = min(dist, man_dist(point))
+print(dist)