Skip to content

Commit

Permalink
22-1
Browse files Browse the repository at this point in the history
  • Loading branch information
koosvary committed Dec 22, 2024
1 parent ed2e4f1 commit 76656e7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
31 changes: 31 additions & 0 deletions 2024/22/22-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import math

def mixThenPrune(secretNumber, multiplying, mutator):
if multiplying:
newSecretNumber = secretNumber * mutator
else:
newSecretNumber = math.floor(secretNumber / mutator)

# mix
newSecretNumber = secretNumber ^ newSecretNumber

# prune
newSecretNumber %= 16777216

return newSecretNumber

total = 0
with open('2024/22/input.txt') as f:
for line in f:
line = line.strip()

secretNumber = int(line)
for i in range(2000):
secretNumber = mixThenPrune(secretNumber, True, 64)
secretNumber = mixThenPrune(secretNumber, False, 32)
secretNumber = mixThenPrune(secretNumber, True, 2048)

total += secretNumber

print(total)

4 changes: 4 additions & 0 deletions 2024/22/testinput.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1
10
100
2024

0 comments on commit 76656e7

Please sign in to comment.