summaryrefslogtreecommitdiff
path: root/day15
diff options
context:
space:
mode:
authorCody Hiar <cody@hiar.ca>2021-04-16 12:03:47 -0600
committerCody Hiar <cody@hiar.ca>2021-04-16 12:03:47 -0600
commit8b154828669acb002148988cfebad586c680ff36 (patch)
treeec1c10195bd5536e7ac0fde5e6a6e6cc429f1120 /day15
parentca1bbfe443ca72b9e8f27257a2df60a862251296 (diff)
day 15 part 1
Diffstat (limited to 'day15')
-rw-r--r--day15/day15.py32
-rw-r--r--day15/input1
2 files changed, 33 insertions, 0 deletions
diff --git a/day15/day15.py b/day15/day15.py
new file mode 100644
index 0000000..a5660a4
--- /dev/null
+++ b/day15/day15.py
@@ -0,0 +1,32 @@
+"""Day 15."""
+
+
+# reading off numbers
+# starting numbers in input
+# consider the most recently spoken number
+
+# new unique numbers mean the current says zero
+# how far aprat the previous spoken one was
+
+
+with open("input") as f:
+ memory = list(map(int, f.read().rstrip().split(",")))
+
+last_pos = {val: pos + 1 for pos, val in enumerate(memory)}
+
+pos = len(memory) + 1
+for x in range(2020 - pos + 1):
+ last = memory[-1]
+ if memory.count(last) == 1:
+ memory.append(0)
+ else:
+ x = pos - 1
+ y = last_pos[last]
+ val = x - y
+ memory.append(val)
+ last_pos[last] = x
+ if val not in last_pos:
+ last_pos[val] = pos
+ pos += 1
+
+print(memory[-1])
diff --git a/day15/input b/day15/input
new file mode 100644
index 0000000..6557303
--- /dev/null
+++ b/day15/input
@@ -0,0 +1 @@
+0,5,4,1,10,14,7