From 76656e74f8229270d2f611625a05afa96d556c05 Mon Sep 17 00:00:00 2001 From: Lachlan Meyer Date: Sun, 22 Dec 2024 17:11:21 +1100 Subject: [PATCH] 22-1 --- 2024/22/22-1.py | 31 +++++++++++++++++++++++++++++++ 2024/22/testinput.txt | 4 ++++ 2 files changed, 35 insertions(+) create mode 100644 2024/22/22-1.py create mode 100644 2024/22/testinput.txt diff --git a/2024/22/22-1.py b/2024/22/22-1.py new file mode 100644 index 0000000..bae11a8 --- /dev/null +++ b/2024/22/22-1.py @@ -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) + diff --git a/2024/22/testinput.txt b/2024/22/testinput.txt new file mode 100644 index 0000000..322c9db --- /dev/null +++ b/2024/22/testinput.txt @@ -0,0 +1,4 @@ +1 +10 +100 +2024 \ No newline at end of file