aboutsummaryrefslogtreecommitdiffstats
path: root/src/09/solve.py
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-04-07 17:18:18 -0400
committerLouis Burda <quent.burda@gmail.com>2023-04-07 17:19:39 -0400
commit87ab487d59fa85dbe2afa55cc841b02805ae42ca (patch)
treecd90ab715e1b5b5803674045dbafd6d51d27ac90 /src/09/solve.py
parent1bcc82c5bfbde87edd03c01ffdf9ee5934681592 (diff)
downloadaoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.tar.gz
aoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.zip
Reorder days into src
Diffstat (limited to 'src/09/solve.py')
-rw-r--r--src/09/solve.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/09/solve.py b/src/09/solve.py
new file mode 100644
index 0000000..f0aa4bf
--- /dev/null
+++ b/src/09/solve.py
@@ -0,0 +1,43 @@
+import sys
+sys.path.append("../common")
+import aoc
+
+from collections import deque
+
+words = aoc.data.split(" ")
+playercount = int(words[0])
+lastworth = int(words[6])
+
+def highscore(playercount, lastworth):
+ lastworth = lastworth - lastworth % 23
+
+ players = [0 for x in range(playercount)]
+ marbles = deque([0])
+ pos = 0
+ for i in range(1, lastworth+1):
+ if i % 23 == 0:
+ cp = (i-1) % playercount
+ players[cp] += i + marbles[(len(marbles) + pos - 7) % len(marbles)]
+ marbles.rotate((len(marbles) - 1 - pos) + 7)
+ marbles.pop()
+ pos = 0
+ else:
+ if i < 3:
+ pos = 1
+ marbles.rotate(1)
+ marbles.append(i)
+ else:
+ marbles.rotate((len(marbles)- 1 -pos) - 1)
+ marbles.append(i)
+ pos = len(marbles)-1
+
+ return max(players)
+
+
+def solve1(args):
+ return highscore(playercount, lastworth)
+
+def solve2(args):
+ return highscore(playercount, lastworth * 100)
+
+aoc.run(solve1, solve2, sols=[412127, 3482394794])