]> fbox.kageds.com Git - adventofcode.git/commitdiff
Create 5pt1.py
authorCptG9000 <71446401+CptG9000@users.noreply.github.com>
Sun, 5 Dec 2021 22:12:22 +0000 (22:12 +0000)
committerCptG9000 <71446401+CptG9000@users.noreply.github.com>
Sun, 5 Dec 2021 22:12:22 +0000 (22:12 +0000)
Gareth solution Python/5pt1.py [new file with mode: 0644]

diff --git a/Gareth solution Python/5pt1.py b/Gareth solution Python/5pt1.py
new file mode 100644 (file)
index 0000000..7b09c14
--- /dev/null
@@ -0,0 +1,27 @@
+lines = []
+while True:
+    try:
+        a, b, c, d = map(int, input().replace(",", " ").replace(" -> ", " ").split())
+        lines.append([(a, b), (c, d)])
+    except ValueError:
+        break
+x = 0
+for line in lines:
+    if max(line[0]) > x or max(line[1]) > x:
+        x = [max(line[0]), max(line[1])][max(line[0]) < max(line[1])]
+
+diagram = [[0 for i in range(x + 1)] for j in range(x + 1)]
+for line in lines:
+    if line[0][1] == line[1][1]:
+        for i in range(min(line[0][0], line[1][0]), max(line[0][0], line[1][0])+1):
+            diagram[line[0][1]][i] += 1
+    elif line[0][0] == line[1][0]:
+        for i in range(min(line[0][1], line[1][1]), max(line[0][1], line[1][1])+1):
+            diagram[i][line[0][0]] += 1
+count_bigger = 0
+for line in diagram:
+    print(line)
+    for num in line:
+        count_bigger += [0, 1][num > 1]
+
+print(count_bigger)
\ No newline at end of file