Browse Source

Day 3

master
Chris Smith 5 years ago
parent
commit
9c640c2cbc
2 changed files with 1304 additions and 0 deletions
  1. 19
    0
      03.py
  2. 1285
    0
      data/03.txt

+ 19
- 0
03.py View File

@@ -0,0 +1,19 @@
1
+import re
2
+from collections import defaultdict
3
+
4
+with open('data/03.txt', 'r') as file:
5
+    cells = defaultdict(list)
6
+    claims = map(lambda l: map(int, re.findall(r'\d+', l)), file.readlines())
7
+    ids = set()
8
+
9
+    for (cid, x, y, width, height) in claims:
10
+        ids.add(cid)
11
+        for i in range(width):
12
+            for j in range(height):
13
+                cells[(x + i, y + j)].append(cid)
14
+
15
+    overlaps = [c for c in cells.values() if len(c) > 1]
16
+    print(len(overlaps))
17
+
18
+    dupes = set(cid for sublist in overlaps for cid in sublist)
19
+    print(list(ids - dupes)[0])

+ 1285
- 0
data/03.txt
File diff suppressed because it is too large
View File