Browse Source

add day 23

part 2 is heavily non optimized, will take about a day to run on really
modern hardware
Juan José Gutiérrez de Quevedo Pérez 4 months ago
parent
commit
99bf948419
2 changed files with 65 additions and 0 deletions
  1. 27 0
      23/1.py
  2. 38 0
      23/2.py

+ 27 - 0
23/1.py

@@ -0,0 +1,27 @@
+content = [int(x) for x in "156794823"]
+lowest = min(content)
+highest = max(content)
+original_length = len(content)
+for turn in range(100):
+    print("--------------------")
+    print(f"turn {turn+1}")
+    print(content)
+    removed = content[1:4]
+    print(f"removed : {removed}")
+    del(content[1:4])
+    content *= 2
+    destination = content[0] - 1
+    if destination < lowest:
+        destination = highest
+    while destination in removed:
+        destination -= 1
+        if destination < lowest:
+            destination = highest
+    print(f"destination: {destination}")
+    destindex = content.index(destination) + 1
+    content[destindex:destindex] = removed
+    content = content[1:1+original_length]
+
+
+content *= 2
+print(content[content.index(1) + 1: content.index(1) + original_length])

+ 38 - 0
23/2.py

@@ -0,0 +1,38 @@
+def main():
+        current  = 0
+        content = [int(x) for x in "156794823"]
+        highest = max(content)
+        for i in range(highest+1, 1000001):
+            content.append(i)
+        original_length = len(content)
+        lowest = min(content)
+        highest = max(content)
+        turn = 0
+        while turn < 10000000:
+            removed1 = content[current + 1 % 1000000]
+            removed2 = content[current + 2 % 1000000]
+            removed3 = content[current + 3 % 1000000]
+            del(content[current + 1 % 1000000])
+            del(content[current + 1 % 1000000])
+            del(content[current + 1 % 1000000])
+            destination = content[current] - 1
+            if destination < lowest:
+                destination = highest
+            while destination == removed1 or destination == removed2 or destination == removed3:
+                destination -= 1
+                if destination < lowest:
+                    destination = highest
+
+            destindex = content.index(destination)
+            destindex += 1
+            content.insert(destindex, removed3)
+            content.insert(destindex, removed2)
+            content.insert(destindex, removed1)
+            current = current + 1 % 1000000
+            turn += 1
+
+
+        content *= 2
+        print(content[content.index(1) + 1] * content[content.index(1) + 2])
+
+main()