summaryrefslogtreecommitdiff
path: root/2023/06/src/part2.cpp
diff options
context:
space:
mode:
Diffstat (limited to '2023/06/src/part2.cpp')
-rw-r--r--2023/06/src/part2.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/2023/06/src/part2.cpp b/2023/06/src/part2.cpp
new file mode 100644
index 0000000..db35b57
--- /dev/null
+++ b/2023/06/src/part2.cpp
@@ -0,0 +1,50 @@
1#include <iostream>
2#include <fstream>
3#include <sstream>
4#include <cstring>
5#include <vector>
6#include <cmath>
7
8int main(void)
9{
10 long time{};
11 long distance{};
12
13 std::ifstream input{ "resources/input.txt" };
14 if (input.is_open())
15 {
16 long n;
17 std::string line;
18
19 /* Time */
20 std::getline(input,line);
21 for(unsigned char c : line)
22 {
23 if (std::isdigit(c))
24 {
25 time *= 10;
26 time += c - '0';
27 }
28 }
29
30 /* Distance */
31 std::getline(input,line);
32 for(unsigned char c : line)
33 {
34 if (std::isdigit(c))
35 {
36 distance *= 10;
37 distance += c - '0';
38 }
39 }
40
41 }
42 input.close();
43
44 double delta = std::sqrt(time * time - 4 * distance);
45 long from{ static_cast<long>(1 + (time - delta) / 2)};
46 long to{ static_cast<long>(std::ceil((time + delta) / 2)) };
47
48 std::cout << to - from << std::endl;
49 return 0;
50}