-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path03.cpp
55 lines (46 loc) · 1.19 KB
/
03.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
#include <chrono>
#include <iostream>
#include <string>
bool is_valid_triangle(int a, int b, int c) {
return a + b > c && a + c > b && b + c > a;
}
int main() {
auto tstart = std::chrono::high_resolution_clock::now();
int pt1 = 0;
int pt2 = 0;
int a, b, c;
std::string input;
int window[3][3];
int wi = 0;
while (std::getline(std::cin, input)) {
a = std::stoi(&input[0]);
b = std::stoi(&input[5]);
c = std::stoi(&input[10]);
if (is_valid_triangle(a, b, c)) {
pt1++;
}
window[0][wi] = a;
window[1][wi] = b;
window[2][wi] = c;
// every 3 rows
if (wi == 2) {
for (int i = 0; i < 3; i++) {
if (is_valid_triangle(window[i][0], window[i][1], window[i][2])) {
pt2++;
}
}
wi = 0;
} else {
wi++;
}
}
std::cout << "--- Day 3: Squares With Three Sides ---\n";
std::cout << "Part 1: " << pt1 << "\n";
std::cout << "Part 2: " << pt2 << "\n";
auto tstop = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::microseconds>(tstop - tstart);
std::cout << "Time: " << duration.count() << " μs"
<< "\n";
return EXIT_SUCCESS;
}