-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday6.cpp
72 lines (59 loc) · 1.52 KB
/
day6.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using namespace std;
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <math.h>
#include "Helpers/HelperFunctions.h"
int main() {
cout << "Day 6" << endl;
ifstream file(R"(C:\Users\gwen\Documents\2_Programming\Advent of Code\Advent of Code 2023\inputs\day6.txt)");
string str;
vector<string> data;
// 0 - time
// 1 - distance
while (getline(file, str)) {
cout << str << endl;
data.push_back(str);
}
vector<int> times;
vector<int> distances;
string timesCombined;
string distancesCombined;
vector<string> out;
tokenize(data[0], ' ', out);
for (int i = 1; i < out.size(); i++) {
times.push_back(stoi(out[i]));
timesCombined.append(out[i]);
}
out.clear();
tokenize(data[1], ' ', out);
for (int i = 1; i < out.size(); i++) {
distances.push_back(stoi(out[i]));
distancesCombined.append(out[i]);
}
long long sum = 1;
for (int i = 0; i < times.size(); i++) {
int options = 0;
for (int n = 1; n < times[i]; n++) {
int distancePer = (times[i] - n) * n;
if (distancePer > distances[i]) {
options++;
}
}
sum *= options;
}
cout << "Part 1: " << sum << endl;
long long timesSum = stoll(timesCombined);
long long distancesSum = stoll(distancesCombined);
int options = 0;
for (long long n = 1; n < timesSum; n++) {
long long distancePer = (timesSum - n) * n;
if (distancePer > distancesSum) {
options++;
}
}
cout << "Part 2: " << options << endl;
return 0;
}