summaryrefslogtreecommitdiff
path: root/2023/15/src/part1.cpp
diff options
context:
space:
mode:
Diffstat (limited to '2023/15/src/part1.cpp')
-rw-r--r--2023/15/src/part1.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/2023/15/src/part1.cpp b/2023/15/src/part1.cpp
new file mode 100644
index 0000000..6473d20
--- /dev/null
+++ b/2023/15/src/part1.cpp
@@ -0,0 +1,33 @@
1#include <iostream>
2#include <fstream>
3
4int main(int argc, char* argv[])
5{
6 int answer{};
7
8 if (std::ifstream input{ argv[1] }; input.is_open())
9 {
10 std::string line;
11 std::getline(input,line);
12
13 int hash{};
14 for (unsigned char c : line)
15 {
16 if (c == ',')
17 {
18 answer += hash;
19 hash = 0;
20 }
21 else
22 {
23 hash += c;
24 hash *= 17;
25 hash %= 256;
26 }
27 }
28 answer += hash;
29 }
30
31 std::cout << answer << std::endl;
32 return 0;
33}