summaryrefslogtreecommitdiff
path: root/2023/15/src/part1.cpp
blob: 6473d2068d3a406f4a43de5dee853f4a3e782225 (plain) (blame)
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
#include <iostream>
#include <fstream>

int main(int argc, char* argv[])
{
    int answer{};

    if (std::ifstream input{ argv[1] }; input.is_open())
    {
        std::string line;
        std::getline(input,line);

        int hash{};
        for (unsigned char c : line)
        {
            if (c == ',')
            {
                answer += hash;
                hash = 0;
            }
            else
            {
                hash += c;
                hash *= 17;
                hash %= 256;
            }
        }
        answer += hash;
    }

    std::cout << answer << std::endl;
    return 0;
}