diff --git a/2024/22/main.py b/2024/22/main.py new file mode 100644 index 0000000..3de8b9a --- /dev/null +++ b/2024/22/main.py @@ -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()