aboutsummaryrefslogtreecommitdiff
path: root/2020/src/day01.cpp
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2024-01-04 00:32:07 +0100
committerThomas Schmucker <ts@its1.de>2024-01-04 00:32:07 +0100
commit52ac586dcd7c78184d5884b0587f6b2c6fae98c4 (patch)
treeb3fcdeaf2e747d32acd49933257a2d641c322ea1 /2020/src/day01.cpp
parent56e890cec0a28c0a485212ccebfaf774235a79a2 (diff)
downloadadvent-of-code-52ac586dcd7c78184d5884b0587f6b2c6fae98c4.tar.gz
advent-of-code-52ac586dcd7c78184d5884b0587f6b2c6fae98c4.tar.bz2
advent-of-code-52ac586dcd7c78184d5884b0587f6b2c6fae98c4.zip
solutions fpor day 1 & day 2, advent of code 2020
Diffstat (limited to '2020/src/day01.cpp')
-rw-r--r--2020/src/day01.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/2020/src/day01.cpp b/2020/src/day01.cpp
index d2d8629..67f88c4 100644
--- a/2020/src/day01.cpp
+++ b/2020/src/day01.cpp
@@ -32,24 +32,27 @@ process(const vector<long>& values)
32void 32void
33combination(const vector<long>& values, size_t r) 33combination(const vector<long>& values, size_t r)
34{ 34{
35 vector<bool> v(values.size()); 35 vector<bool> marker(values.size());
36 fill(v.end() - long(r), v.end(), true); 36
37 vector<long> set(r); 37 fill(marker.end() - long(r), marker.end(), true);
38
39 vector<long> subset(r);
40
38 do { 41 do {
39 set.clear(); 42 subset.clear();
40 for ( size_t i = 0; i != values.size(); ++i ) { 43 for ( size_t i = 0; i != values.size(); ++i ) {
41 if ( v[i] ) { 44 if ( marker[i] ) {
42 set.emplace_back(values[i]); 45 subset.emplace_back(values[i]);
43 } 46 }
44 } 47 }
45 process(set); 48 process(subset);
46 } while ( std::next_permutation(v.begin(), v.end()) ); 49 } while ( std::next_permutation(marker.begin(), marker.end()) );
47} 50}
48 51
49int 52int
50main() 53main()
51{ 54{
52 auto values = read_file("data/day01-sample1.txt"); 55 auto values = read_file("data/day01.txt");
53 combination(values, 2); 56 combination(values, 2);
54 combination(values, 3); 57 combination(values, 3);
55} 58}