summary refs log tree commit diff stats
path: root/day3.py
diff options
context:
space:
mode:
Diffstat (limited to 'day3.py')
-rw-r--r--day3.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/day3.py b/day3.py
new file mode 100644
index 0000000..8d5854e
--- /dev/null
+++ b/day3.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+
+from collections import defaultdict
+with open('day3.txt') as data:
+    directions = data.read().strip()
+# part 1
+x, y = 0, 0
+houses = defaultdict(int)
+houses[(x, y)] = 1
+for direction in directions:
+    match direction:
+        case '^':
+            y += 1
+        case 'v':
+            y -= 1
+        case '>':
+            x += 1
+        case '<':
+            x -= 1
+    houses[(x, y)] += 1
+
+print(len(houses))
+
+# part 2
+santaX, santaY, roboX, roboY = 0, 0, 0, 0
+houses = defaultdict(int)
+houses[(0, 0)] = 2
+isSanta = True
+for direction in directions:
+    if isSanta:
+        match direction:
+            case '^':
+                santaY += 1
+            case 'v':
+                santaY -= 1
+            case '>':
+                santaX += 1
+            case '<':
+                santaX -= 1
+        houses[(santaX, santaY)] += 1
+    else:
+        match direction:
+            case '^':
+                roboY += 1
+            case 'v':
+                roboY -= 1
+            case '>':
+                roboX += 1
+            case '<':
+                roboX -= 1
+        houses[(roboX, roboY)] += 1
+    isSanta = not isSanta
+print(len(houses))