summaryrefslogtreecommitdiff
path: root/2023/09/src/part1.cpp
blob: 4087486fcf74ec0fc0b622282d13d42260fba572 (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
34
35
36
37
38
39
40
41
42
43
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>

void solve(std::vector<int> v, int& answer)
{
    for (int a = v.size() - 1; a > 0; --a)
    {
        answer += v[a];
        for (int b = 0; b < a; ++b)
        {
            v[b] = v[b+1] - v[b];
        }
    }
}

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

    std::ifstream input{ argv[1] };
    if (input.is_open())
    {
        std::string line;
        while (not std::getline(input,line).eof())
        {
            int n;
            std::vector<int> v{};
            std::istringstream sline{ line };
            while(sline >> n)
            {
                v.push_back(n);
            }

            solve(std::move(v), answer);
        }
    }
    input.close();

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