From 2804a9ced3ffa0df178621e0c5930b1cb380f2f8 Mon Sep 17 00:00:00 2001 From: KaterynaKateryna Date: Sun, 22 Dec 2024 22:25:21 +0100 Subject: [PATCH] day 22 part 1 --- AdventOfCode/Day22.cs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 AdventOfCode/Day22.cs diff --git a/AdventOfCode/Day22.cs b/AdventOfCode/Day22.cs new file mode 100644 index 0000000..4bf8405 --- /dev/null +++ b/AdventOfCode/Day22.cs @@ -0,0 +1,39 @@ + +namespace AdventOfCode; + +public class Day22 : BaseDay +{ + public override ValueTask Solve_1() + { + long[] numbers = File.ReadAllLines(InputFilePath).Select(long.Parse).ToArray(); + + long result = numbers.Sum(n => GetIteration(n, 2000)); + + return new(result.ToString()); + } + + public override ValueTask Solve_2() + { + return new(""); + } + + private long GetIteration(long number, int iterations) + { + for (int i = 0; i < iterations; ++i) + { + // 1 + number = (number << 6) ^ number; + number = number % 16777216; + + // 2 + number = (number / 32) ^ number; + number = number % 16777216; + + // 3 + number = (number << 11) ^ number; + number = number % 16777216; + } + + return number; + } +}