File tree 5 files changed +1098
-0
lines changed
5 files changed +1098
-0
lines changed Original file line number Diff line number Diff line change
1
+ .vscode /
2
+
3
+ ** /* .out
4
+
5
+ test.cpp
6
+ test
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+ #include " ../utils.hpp"
4
+
5
+ using namespace std ;
6
+
7
+ int main ()
8
+ {
9
+ string input_text = aoc_utils::readFile (" ../inputs/01.txt" );
10
+ vector<string> calibration_doc = aoc_utils::split_string (input_text, " \n " );
11
+
12
+ vector<int > calibration_values;
13
+
14
+ for (string line : calibration_doc)
15
+ {
16
+ vector<char > line_numbers;
17
+ for (char & ch : line)
18
+ {
19
+ if (isdigit (ch))
20
+ {
21
+ line_numbers.push_back (ch);
22
+ }
23
+ }
24
+
25
+ string value;
26
+ value += line_numbers.front ();
27
+ value += line_numbers.back ();
28
+
29
+ calibration_values.push_back (stoi (value));
30
+ }
31
+
32
+ int sum_of_values = 0 ;
33
+
34
+ for (int val : calibration_values)
35
+ sum_of_values += val;
36
+
37
+ cout << sum_of_values << endl;
38
+ }
Original file line number Diff line number Diff line change
1
+ # aoc-2023
2
+
3
+ I'll try finishing it this time (lie)
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ #pragma once
2
+ #include < iostream>
3
+ #include < fstream>
4
+ #include < sstream>
5
+ #include < vector>
6
+ #include < algorithm>
7
+
8
+ using namespace std ;
9
+
10
+ namespace aoc_utils
11
+ {
12
+ string readFile (string fn)
13
+ {
14
+ ifstream file;
15
+ file.open (filesystem::canonical (fn));
16
+
17
+ stringstream outstring;
18
+ string line;
19
+ while (getline (file, line))
20
+ {
21
+ outstring << line << ' \n ' ;
22
+ }
23
+
24
+ file.close ();
25
+
26
+ return outstring.str ();
27
+ }
28
+ vector<string> split_string (string &to_split, string delim)
29
+ {
30
+ string throwaway = to_split;
31
+ vector<string> out;
32
+
33
+ size_t pos = 0 ;
34
+ string token;
35
+ while ((pos = throwaway.find (delim)) != string::npos) {
36
+ token = throwaway.substr (0 , pos);
37
+ out.push_back (token);
38
+ throwaway.erase (0 , pos + delim.length ());
39
+ }
40
+ // last item is out of the loop and becomes throwaway (aka to_split)
41
+ if (!throwaway.empty ())
42
+ out.push_back (throwaway);
43
+
44
+ return out;
45
+ }
46
+
47
+ int char_to_int (char & val)
48
+ {
49
+ return val - ' 0' ;
50
+ }
51
+ }
You can’t perform that action at this time.
0 commit comments