aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2024-01-03 23:35:54 +0100
committerThomas Schmucker <ts@its1.de>2024-01-03 23:35:54 +0100
commit56e890cec0a28c0a485212ccebfaf774235a79a2 (patch)
treed9c6241a1aa247e06ab5ba2f6f11967b77d458ec
parente9a1cb0441d137d7a26cb303b7e72d3424b7392d (diff)
downloadadvent-of-code-56e890cec0a28c0a485212ccebfaf774235a79a2.tar.gz
advent-of-code-56e890cec0a28c0a485212ccebfaf774235a79a2.tar.bz2
advent-of-code-56e890cec0a28c0a485212ccebfaf774235a79a2.zip
prepare for more puzzles ... :)
-rw-r--r--.gitignore4
-rw-r--r--2020/data/.gitkeep (renamed from data/.gitkeep)0
-rw-r--r--2020/src/day01.cpp55
-rw-r--r--2023/data/.gitkeep0
-rw-r--r--2023/src/day01.cpp (renamed from src/day01.cpp)0
-rw-r--r--2023/src/day02.cpp (renamed from src/day02.cpp)2
-rw-r--r--2023/src/day03.cpp (renamed from src/day03.cpp)0
-rw-r--r--2023/src/day04.cpp (renamed from src/day04.cpp)0
-rw-r--r--2023/src/day05.cpp (renamed from src/day05.cpp)0
-rw-r--r--2023/src/day06.cpp (renamed from src/day06.cpp)0
-rw-r--r--2023/src/day07.cpp (renamed from src/day07.cpp)0
-rw-r--r--2023/src/day08.cpp (renamed from src/day08.cpp)0
-rw-r--r--2023/src/day09.cpp (renamed from src/day09.cpp)0
-rw-r--r--2023/src/day10.cpp (renamed from src/day10.cpp)0
-rw-r--r--2023/src/day11.cpp (renamed from src/day11.cpp)0
-rw-r--r--2023/src/day12.cpp (renamed from src/day12.cpp)0
-rw-r--r--2023/src/day13.cpp (renamed from src/day13.cpp)0
-rw-r--r--2023/src/day14.cpp (renamed from src/day14.cpp)0
-rw-r--r--2023/src/day15.cpp (renamed from src/day15.cpp)0
-rw-r--r--2023/src/day16.cpp (renamed from src/day16.cpp)0
-rw-r--r--2023/src/day17.cpp (renamed from src/day17.cpp)0
-rw-r--r--2023/src/day18.cpp (renamed from src/day18.cpp)0
-rw-r--r--2023/src/day19.cpp (renamed from src/day19.cpp)0
-rw-r--r--2023/src/day20.cpp (renamed from src/day20.cpp)0
-rw-r--r--2023/src/day21.cpp (renamed from src/day21.cpp)0
-rw-r--r--2023/src/day22.cpp (renamed from src/day22.cpp)0
-rw-r--r--2023/src/day23.cpp (renamed from src/day23.cpp)0
-rw-r--r--2023/src/day24.cpp (renamed from src/day24.cpp)0
-rw-r--r--2023/src/day25.cpp (renamed from src/day25.cpp)0
-rw-r--r--makefile42
30 files changed, 70 insertions, 33 deletions
diff --git a/.gitignore b/.gitignore
index afa46c7..df07bbc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
1bin/ 1*/bin/
2data/*.txt 2*/data/*.txt
3.gdb_history 3.gdb_history
diff --git a/data/.gitkeep b/2020/data/.gitkeep
index e69de29..e69de29 100644
--- a/data/.gitkeep
+++ b/2020/data/.gitkeep
diff --git a/2020/src/day01.cpp b/2020/src/day01.cpp
new file mode 100644
index 0000000..d2d8629
--- /dev/null
+++ b/2020/src/day01.cpp
@@ -0,0 +1,55 @@
1#include <fstream>
2#include <functional>
3#include <iostream>
4#include <string>
5#include <vector>
6#include <numeric>
7using namespace std;
8
9auto
10read_file(string_view filename)
11{
12 fstream input{ filename };
13 vector<long> data;
14
15 for ( long value = 0; input >> value; ) {
16 data.emplace_back(value);
17 }
18
19 return data;
20}
21
22void
23process(const vector<long>& values)
24{
25 const long year = 2020;
26
27 if (accumulate(values.begin(), values.end(), 0L) == year) {
28 cout << accumulate(values.begin(), values.end(), 1, multiplies<>()) << endl;
29 }
30}
31
32void
33combination(const vector<long>& values, size_t r)
34{
35 vector<bool> v(values.size());
36 fill(v.end() - long(r), v.end(), true);
37 vector<long> set(r);
38 do {
39 set.clear();
40 for ( size_t i = 0; i != values.size(); ++i ) {
41 if ( v[i] ) {
42 set.emplace_back(values[i]);
43 }
44 }
45 process(set);
46 } while ( std::next_permutation(v.begin(), v.end()) );
47}
48
49int
50main()
51{
52 auto values = read_file("data/day01-sample1.txt");
53 combination(values, 2);
54 combination(values, 3);
55}
diff --git a/2023/data/.gitkeep b/2023/data/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/2023/data/.gitkeep
diff --git a/src/day01.cpp b/2023/src/day01.cpp
index ff357bc..ff357bc 100644
--- a/src/day01.cpp
+++ b/2023/src/day01.cpp
diff --git a/src/day02.cpp b/2023/src/day02.cpp
index df560c3..aa3d5a2 100644
--- a/src/day02.cpp
+++ b/2023/src/day02.cpp
@@ -11,7 +11,7 @@ using namespace std;
11vector<string> 11vector<string>
12split(const string& line, char sep) 12split(const string& line, char sep)
13{ 13{
14 vector<string> parts{}; 14 vector<string> parts;
15 stringstream input{ line }; 15 stringstream input{ line };
16 16
17 for ( string part; getline(input, part, sep); ) { 17 for ( string part; getline(input, part, sep); ) {
diff --git a/src/day03.cpp b/2023/src/day03.cpp
index b266f59..b266f59 100644
--- a/src/day03.cpp
+++ b/2023/src/day03.cpp
diff --git a/src/day04.cpp b/2023/src/day04.cpp
index 0d3e552..0d3e552 100644
--- a/src/day04.cpp
+++ b/2023/src/day04.cpp
diff --git a/src/day05.cpp b/2023/src/day05.cpp
index 42fda29..42fda29 100644
--- a/src/day05.cpp
+++ b/2023/src/day05.cpp
diff --git a/src/day06.cpp b/2023/src/day06.cpp
index 9a429c5..9a429c5 100644
--- a/src/day06.cpp
+++ b/2023/src/day06.cpp
diff --git a/src/day07.cpp b/2023/src/day07.cpp
index 1f44ac5..1f44ac5 100644
--- a/src/day07.cpp
+++ b/2023/src/day07.cpp
diff --git a/src/day08.cpp b/2023/src/day08.cpp
index 3e1b6c9..3e1b6c9 100644
--- a/src/day08.cpp
+++ b/2023/src/day08.cpp
diff --git a/src/day09.cpp b/2023/src/day09.cpp
index 4b30e6e..4b30e6e 100644
--- a/src/day09.cpp
+++ b/2023/src/day09.cpp
diff --git a/src/day10.cpp b/2023/src/day10.cpp
index 264e111..264e111 100644
--- a/src/day10.cpp
+++ b/2023/src/day10.cpp
diff --git a/src/day11.cpp b/2023/src/day11.cpp
index e1a0882..e1a0882 100644
--- a/src/day11.cpp
+++ b/2023/src/day11.cpp
diff --git a/src/day12.cpp b/2023/src/day12.cpp
index 11bd80b..11bd80b 100644
--- a/src/day12.cpp
+++ b/2023/src/day12.cpp
diff --git a/src/day13.cpp b/2023/src/day13.cpp
index 549457b..549457b 100644
--- a/src/day13.cpp
+++ b/2023/src/day13.cpp
diff --git a/src/day14.cpp b/2023/src/day14.cpp
index 8816ce1..8816ce1 100644
--- a/src/day14.cpp
+++ b/2023/src/day14.cpp
diff --git a/src/day15.cpp b/2023/src/day15.cpp
index 6fcbfc2..6fcbfc2 100644
--- a/src/day15.cpp
+++ b/2023/src/day15.cpp
diff --git a/src/day16.cpp b/2023/src/day16.cpp
index 93c7479..93c7479 100644
--- a/src/day16.cpp
+++ b/2023/src/day16.cpp
diff --git a/src/day17.cpp b/2023/src/day17.cpp
index 4098bba..4098bba 100644
--- a/src/day17.cpp
+++ b/2023/src/day17.cpp
diff --git a/src/day18.cpp b/2023/src/day18.cpp
index 3037739..3037739 100644
--- a/src/day18.cpp
+++ b/2023/src/day18.cpp
diff --git a/src/day19.cpp b/2023/src/day19.cpp
index a1d4eab..a1d4eab 100644
--- a/src/day19.cpp
+++ b/2023/src/day19.cpp
diff --git a/src/day20.cpp b/2023/src/day20.cpp
index f85ac90..f85ac90 100644
--- a/src/day20.cpp
+++ b/2023/src/day20.cpp
diff --git a/src/day21.cpp b/2023/src/day21.cpp
index c633155..c633155 100644
--- a/src/day21.cpp
+++ b/2023/src/day21.cpp
diff --git a/src/day22.cpp b/2023/src/day22.cpp
index 1afb994..1afb994 100644
--- a/src/day22.cpp
+++ b/2023/src/day22.cpp
diff --git a/src/day23.cpp b/2023/src/day23.cpp
index d8c20d3..d8c20d3 100644
--- a/src/day23.cpp
+++ b/2023/src/day23.cpp
diff --git a/src/day24.cpp b/2023/src/day24.cpp
index 76f459b..76f459b 100644
--- a/src/day24.cpp
+++ b/2023/src/day24.cpp
diff --git a/src/day25.cpp b/2023/src/day25.cpp
index 1d5e19e..1d5e19e 100644
--- a/src/day25.cpp
+++ b/2023/src/day25.cpp
diff --git a/makefile b/makefile
index 1849790..e1318c1 100644
--- a/makefile
+++ b/makefile
@@ -1,41 +1,23 @@
1include config.mk 1include config.mk
2 2
3all: bin/day01 \ 3all: $(patsubst 2020/src/%.cpp,2020/bin/%,$(wildcard 2020/src/*.cpp)) \
4 bin/day02 \ 4 $(patsubst 2023/src/%.cpp,2023/bin/%,$(wildcard 2023/src/*.cpp))
5 bin/day03 \
6 bin/day04 \
7 bin/day05 \
8 bin/day06 \
9 bin/day07 \
10 bin/day08 \
11 bin/day09 \
12 bin/day10 \
13 bin/day11 \
14 bin/day12 \
15 bin/day13 \
16 bin/day14 \
17 bin/day15 \
18 bin/day16 \
19 bin/day17 \
20 bin/day18 \
21 bin/day19 \
22 bin/day20 \
23 bin/day21 \
24 bin/day22 \
25 bin/day23 \
26 bin/day24 \
27 bin/day25
28 5
29bin: 6%/bin:
30 mkdir $@ 7 mkdir -p $@
31 8
32bin/%: src/%.cpp | bin 9# 2020
102020/bin/%: 2020/src/%.cpp | 2020/bin
33 c++ $(CPPFLAGS) $^ -o $@ 11 c++ $(CPPFLAGS) $^ -o $@
34 12
35bin/day24: src/day24.cpp | bin 13# 2023
142023/bin/%: 2023/src/%.cpp | 2023/bin
15 c++ $(CPPFLAGS) $^ -o $@
16
172023/bin/day24: 2023/src/day24.cpp | 2023/bin
36 c++ $(CPPFLAGS) -Wno-sign-conversion -I/usr/local/include $^ -L/usr/local/lib -lz3 -o $@ 18 c++ $(CPPFLAGS) -Wno-sign-conversion -I/usr/local/include $^ -L/usr/local/lib -lz3 -o $@
37 19
38clean: 20clean:
39 rm -rf bin 21 rm -rf 2020/bin 2023/bin
40 22
41.PHONY: all clean 23.PHONY: all clean