summaryrefslogtreecommitdiff
path: root/2023/01/src/part1.cpp
diff options
context:
space:
mode:
Diffstat (limited to '2023/01/src/part1.cpp')
-rw-r--r--2023/01/src/part1.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/2023/01/src/part1.cpp b/2023/01/src/part1.cpp
new file mode 100644
index 0000000..3034d43
--- /dev/null
+++ b/2023/01/src/part1.cpp
@@ -0,0 +1,37 @@
1#include <iostream>
2#include <fstream>
3
4template<typename Iter>
5int search(Iter from, Iter to)
6{
7 while(from < to)
8 {
9 char c = *(from++);
10 if (std::isdigit(c))
11 {
12 return c - '0';
13 }
14 }
15 return 0;
16}
17
18int main(void)
19{
20 int answer{};
21
22 std::ifstream input{ "./resources/input.txt" };
23 if (input)
24 {
25 std::string line;
26 while(not std::getline(input, line).eof())
27 {
28 answer += 10 * search(line.begin(), line.end());
29 answer += search(line.rbegin(), line.rend());
30 }
31
32 }
33 input.close();
34
35 std::cout << answer << std::endl;
36 return 0;
37}