aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2025-12-01 12:48:55 +0100
committerThomas Schmucker <ts@its1.de>2025-12-01 12:48:55 +0100
commit628b7b45df8e78f4ba759760987f65b978e188f5 (patch)
tree9fd37dfb744d0003e708e2953d9cea0602d1796d
parentbdd35a7bee7f23c912d0c453abc263805d8d8ccf (diff)
downloadadvent-of-code-628b7b45df8e78f4ba759760987f65b978e188f5.tar.gz
advent-of-code-628b7b45df8e78f4ba759760987f65b978e188f5.tar.bz2
advent-of-code-628b7b45df8e78f4ba759760987f65b978e188f5.zip
aoc 2025, day 1
-rw-r--r--2025/data/.gitkeep0
-rw-r--r--2025/src/day01.cpp67
-rw-r--r--makefile9
3 files changed, 74 insertions, 2 deletions
diff --git a/2025/data/.gitkeep b/2025/data/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/2025/data/.gitkeep
diff --git a/2025/src/day01.cpp b/2025/src/day01.cpp
new file mode 100644
index 0000000..aa1ea42
--- /dev/null
+++ b/2025/src/day01.cpp
@@ -0,0 +1,67 @@
1#include <filesystem>
2#include <fstream>
3#include <iostream>
4#include <string>
5#include <vector>
6
7using namespace std;
8
9namespace {
10
11vector<string>
12read_file(const filesystem::path& filename)
13{
14 ifstream file{ filename };
15 vector<string> lines;
16
17 for ( string line; getline(file, line); ) {
18 lines.emplace_back(line);
19 }
20
21 return lines;
22}
23
24void
25part1(const vector<string>& lines)
26{
27 auto zeros = 0;
28 auto pos = 50;
29
30 for ( const auto& line: lines ) {
31 auto value = stoi(line.substr(1));
32 value %= 100;
33 pos += (line[0] == 'L') ? (100 - value) : value;
34 if ( pos % 100 == 0 ) {
35 ++zeros;
36 }
37 }
38 cout << "Part 1: " << zeros << '\n';
39}
40
41void
42part2(const vector<string>& lines)
43{
44 auto zeros = 0;
45 auto pos = 50;
46
47 for ( const auto& line: lines ) {
48 auto value = stoi(line.substr(1));
49 while ( value-- > 0 ) {
50 pos += (line[0] == 'L') ? 99 : 1;
51 if ( pos % 100 == 0 ) {
52 ++zeros;
53 }
54 }
55 }
56 cout << "Part 2: " << zeros << '\n';
57}
58
59} // namespace
60
61int
62main()
63{
64 auto data = read_file("data/day01.txt");
65 part1(data);
66 part2(data);
67}
diff --git a/makefile b/makefile
index 22a1c4b..634c220 100644
--- a/makefile
+++ b/makefile
@@ -6,7 +6,8 @@ all: $(patsubst 2015/src/%.cpp,2015/bin/%,$(wildcard 2015/src/*.cpp)) \
6 $(patsubst 2020/src/%.cpp,2020/bin/%,$(wildcard 2020/src/*.cpp)) \ 6 $(patsubst 2020/src/%.cpp,2020/bin/%,$(wildcard 2020/src/*.cpp)) \
7 $(patsubst 2022/src/%.cpp,2022/bin/%,$(wildcard 2022/src/*.cpp)) \ 7 $(patsubst 2022/src/%.cpp,2022/bin/%,$(wildcard 2022/src/*.cpp)) \
8 $(patsubst 2023/src/%.cpp,2023/bin/%,$(wildcard 2023/src/*.cpp)) \ 8 $(patsubst 2023/src/%.cpp,2023/bin/%,$(wildcard 2023/src/*.cpp)) \
9 $(patsubst 2024/src/%.cpp,2024/bin/%,$(wildcard 2024/src/*.cpp)) 9 $(patsubst 2024/src/%.cpp,2024/bin/%,$(wildcard 2024/src/*.cpp)) \
10 $(patsubst 2025/src/%.cpp,2025/bin/%,$(wildcard 2025/src/*.cpp))
10 11
11%/bin: 12%/bin:
12 mkdir -p $@ 13 mkdir -p $@
@@ -57,7 +58,11 @@ all: $(patsubst 2015/src/%.cpp,2015/bin/%,$(wildcard 2015/src/*.cpp)) \
572024/bin/day13-z3: 2024/src/day13-z3.cpp | 2024/bin 582024/bin/day13-z3: 2024/src/day13-z3.cpp | 2024/bin
58 c++ $(CPPFLAGS) $^ -lz3 -o $@ 59 c++ $(CPPFLAGS) $^ -lz3 -o $@
59 60
61# 2025
622025/bin/%: 2025/src/%.cpp | 2025/bin
63 c++ $(CPPFLAGS) $^ -o $@
64
60clean: 65clean:
61 rm -rf 2015/bin 2016/bin 2017/bin 2020/bin 2022/bin 2023/bin 2024/bin 66 rm -rf 2015/bin 2016/bin 2017/bin 2020/bin 2022/bin 2023/bin 2024/bin 2025/bin
62 67
63.PHONY: all clean 68.PHONY: all clean