add 2024/day22.1
This commit is contained in:
parent
b8f58fdfa5
commit
b660b89a65
1 changed files with 48 additions and 0 deletions
48
2024/22/main.py
Normal file
48
2024/22/main.py
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- encoding: utf-8; py-indent-offset: 4 -*-
|
||||||
|
|
||||||
|
# Author: Sebastian Mark
|
||||||
|
# CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de)
|
||||||
|
|
||||||
|
# pylint: disable=missing-module-docstring,missing-function-docstring,consider-using-f-string
|
||||||
|
|
||||||
|
|
||||||
|
def readinput():
|
||||||
|
with open("input", "r", encoding="utf-8") as file:
|
||||||
|
lines = [int(line.strip()) for line in file.readlines()]
|
||||||
|
return lines
|
||||||
|
|
||||||
|
|
||||||
|
def mix_and_prune(i: int, j: int) -> int:
|
||||||
|
return (i ^ j) % 16777216
|
||||||
|
|
||||||
|
|
||||||
|
def calc_number(num: int) -> int:
|
||||||
|
for _ in range(2000):
|
||||||
|
# step 1
|
||||||
|
tmp = num * 64
|
||||||
|
num = mix_and_prune(num, tmp)
|
||||||
|
|
||||||
|
# step 2
|
||||||
|
tmp = num // 32
|
||||||
|
num = mix_and_prune(num, tmp)
|
||||||
|
|
||||||
|
# step 3
|
||||||
|
tmp = num * 2048
|
||||||
|
num = mix_and_prune(num, tmp)
|
||||||
|
|
||||||
|
return num
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
intial_numbers = readinput()
|
||||||
|
|
||||||
|
# part 1
|
||||||
|
new_numbers = {}
|
||||||
|
for num in intial_numbers:
|
||||||
|
new_numbers[num] = calc_number(num)
|
||||||
|
print("Sum: %d" % sum(new_numbers.values()))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in a new issue