aboutsummaryrefslogtreecommitdiff
path: root/2024/src/day22.cpp
blob: b10398637448624508a3c5f43b59b36124e027d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;

vector<unsigned long>
read_file(string_view filename)
{
	fstream               input{ filename };
	vector<unsigned long> lines;

	for ( unsigned long value{}; input >> value; ) {
		lines.emplace_back(value);
	}

	return lines;
}

unsigned long
step(unsigned long value)
{
	value = (value ^ (value * 64)) % 16777216;
	value = (value ^ (value / 32)) % 16777216;
	value = (value ^ (value * 2048)) % 16777216;
	return value;
}

void
part1(const vector<unsigned long>& values)
{
	unsigned long sum = 0;
	for ( auto value: values ) {
		for ( int i = 0; i != 2000; ++i ) {
			value = step(value);
		}
		sum += value;
	}
	cout << sum << endl;
}

int
main()
{
	auto data = read_file("data/day22.txt");
	part1(data);
}