summaryrefslogtreecommitdiffstats
path: root/day01
diff options
context:
space:
mode:
authorOrfeas <38209077+0xfea5@users.noreply.github.com>2025-12-04 02:16:03 +0200
committerOrfeas <38209077+0xfea5@users.noreply.github.com>2025-12-04 02:16:03 +0200
commitc4424072e08da92a2dbe6e99f0135371368c7866 (patch)
treef3c43c8a5e6c2cf87def71c754fc1076d565d6aa /day01
parentadd skel/ directory (diff)
downloadaoc25-c4424072e08da92a2dbe6e99f0135371368c7866.tar.gz
aoc25-c4424072e08da92a2dbe6e99f0135371368c7866.zip
day01
Diffstat (limited to 'day01')
-rw-r--r--day01/Makefile1
-rw-r--r--day01/solution.cpp69
-rw-r--r--day01/tests/test1.input10
-rw-r--r--day01/tests/test1.output2
-rw-r--r--day01/tests/test2.input1
-rw-r--r--day01/tests/test2.output2
6 files changed, 85 insertions, 0 deletions
diff --git a/day01/Makefile b/day01/Makefile
new file mode 100644
index 0000000..2fa98c0
--- /dev/null
+++ b/day01/Makefile
@@ -0,0 +1 @@
include ../aoc.mk
diff --git a/day01/solution.cpp b/day01/solution.cpp
new file mode 100644
index 0000000..9fb9ec1
--- /dev/null
+++ b/day01/solution.cpp
@@ -0,0 +1,69 @@
1#include <bits/stdc++.h>
2
3namespace views = std::views;
4namespace ranges = std::ranges;
5
6auto parse_input(std::istream& is) {
7 const std::string input = {
8 std::istreambuf_iterator<char>(is),
9 std::istreambuf_iterator<char>()
10 };
11
12 auto lines = views::split(input, '\n') | views::filter([](auto line) { return not line.empty(); });
13 std::vector<int> document;
14 for (auto const line : lines) {
15 char direction = line[0];
16 std::string out;
17 ranges::copy(line | views::drop(1), std::back_inserter(out));
18 int length = std::stoi(out);
19 document.push_back(direction == 'R' ? length : -length);
20 }
21 return document;
22}
23
24int const DIAL_MAX = 100;
25
26void part1(auto const& input) {
27 // Write first part solution here
28 int answer = 0;
29 int dial = 50;
30
31 for (auto const offset : input) {
32 dial += offset;
33 dial %= DIAL_MAX;
34 if (dial == 0) {
35 ++answer;
36 }
37 }
38
39 std::println("{}", answer);
40}
41
42void part2(auto const& input) {
43 // Write second part solution here
44 int answer = 0;
45 int dial = 50;
46 int sign = 1;
47
48 for (auto const offset : input) {
49 int old_dial = dial;
50 dial += offset;
51 answer += std::abs(dial / DIAL_MAX);
52 if (old_dial * dial < 0 or dial == 0) {
53 ++answer;
54 }
55 dial %= DIAL_MAX;
56 old_dial = dial;
57 std::cerr << answer << ' ' << dial << '\n';
58 }
59 std::println("{}", answer);
60}
61
62int main() {
63 auto const input = parse_input(std::cin);
64
65 part1(input);
66 part2(input);
67
68 return 0;
69}
diff --git a/day01/tests/test1.input b/day01/tests/test1.input
new file mode 100644
index 0000000..53287c7
--- /dev/null
+++ b/day01/tests/test1.input
@@ -0,0 +1,10 @@
1L68
2L30
3R48
4L5
5R60
6L55
7L1
8L99
9R14
10L82
diff --git a/day01/tests/test1.output b/day01/tests/test1.output
new file mode 100644
index 0000000..2559e5c
--- /dev/null
+++ b/day01/tests/test1.output
@@ -0,0 +1,2 @@
13
26
diff --git a/day01/tests/test2.input b/day01/tests/test2.input
new file mode 100644
index 0000000..af158bd
--- /dev/null
+++ b/day01/tests/test2.input
@@ -0,0 +1 @@
L150 \ No newline at end of file
diff --git a/day01/tests/test2.output b/day01/tests/test2.output
new file mode 100644
index 0000000..1191247
--- /dev/null
+++ b/day01/tests/test2.output
@@ -0,0 +1,2 @@
11
22