aboutsummaryrefslogtreecommitdiff
path: root/2024/src
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2024-12-22 17:55:21 +0100
committerThomas Schmucker <ts@its1.de>2024-12-22 17:55:21 +0100
commit2f1784a972ea58152b34fda2ce61bfc71cd1a8b2 (patch)
tree7bf581f624414cfa741bb1689346840b6bff9cf1 /2024/src
parent8427e039c3a99d1cb7a543a06f9d63897df9f294 (diff)
downloadadvent-of-code-2f1784a972ea58152b34fda2ce61bfc71cd1a8b2.tar.gz
advent-of-code-2f1784a972ea58152b34fda2ce61bfc71cd1a8b2.tar.bz2
advent-of-code-2f1784a972ea58152b34fda2ce61bfc71cd1a8b2.zip
aoc 2024, day 22, part 1
Diffstat (limited to '2024/src')
-rw-r--r--2024/src/day22.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/2024/src/day22.cpp b/2024/src/day22.cpp
new file mode 100644
index 0000000..b103986
--- /dev/null
+++ b/2024/src/day22.cpp
@@ -0,0 +1,47 @@
1#include <cstdlib>
2#include <fstream>
3#include <iostream>
4#include <vector>
5using namespace std;
6
7vector<unsigned long>
8read_file(string_view filename)
9{
10 fstream input{ filename };
11 vector<unsigned long> lines;
12
13 for ( unsigned long value{}; input >> value; ) {
14 lines.emplace_back(value);
15 }
16
17 return lines;
18}
19
20unsigned long
21step(unsigned long value)
22{
23 value = (value ^ (value * 64)) % 16777216;
24 value = (value ^ (value / 32)) % 16777216;
25 value = (value ^ (value * 2048)) % 16777216;
26 return value;
27}
28
29void
30part1(const vector<unsigned long>& values)
31{
32 unsigned long sum = 0;
33 for ( auto value: values ) {
34 for ( int i = 0; i != 2000; ++i ) {
35 value = step(value);
36 }
37 sum += value;
38 }
39 cout << sum << endl;
40}
41
42int
43main()
44{
45 auto data = read_file("data/day22.txt");
46 part1(data);
47}