diff options
author | kaiwu <kaiwu2004@gmail.com> | 2022-04-20 22:43:02 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2022-04-20 22:43:02 +0800 |
commit | 09d7a8a34030b49d2316538949ad84668c42b8ca (patch) | |
tree | 265925b30e203685910e0de0393c992c10a2eba3 /src/2019/day7/aoc.cpp | |
parent | cf2fa8493234e8f66468793d9b4a7633c3704a14 (diff) | |
download | advent-of-code-09d7a8a34030b49d2316538949ad84668c42b8ca.tar.gz advent-of-code-09d7a8a34030b49d2316538949ad84668c42b8ca.zip |
loopback computer
Diffstat (limited to 'src/2019/day7/aoc.cpp')
-rw-r--r-- | src/2019/day7/aoc.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/2019/day7/aoc.cpp b/src/2019/day7/aoc.cpp index 176683a..d654a0c 100644 --- a/src/2019/day7/aoc.cpp +++ b/src/2019/day7/aoc.cpp @@ -1,5 +1,6 @@ #include "aoc.h" #include "../day5/aoc.h" +#include <algorithm> #include <set> namespace aoc2019 { @@ -45,10 +46,7 @@ static void get_number(const char** pp, int* d) { *pp = p; } -int day7(line_view file) { - int max{INT32_MIN}; - int is[10] = {0}; - std::set<int> ns; +std::pair<int, int> day7(line_view file) { std::vector<int> codes; const char* p = file.line; while (p < file.line + file.length) { @@ -59,7 +57,22 @@ int day7(line_view file) { } p++; } - find_max(is, 0, ns, &max, codes); - return max; + int m1{INT32_MIN}; + int is1[10] = {0}; + std::set<int> ns1; + find_max(is1, 0, ns1, &m1, codes); + + for (int i : {5, 6, 7, 8, 9}) { + int is2[10] = {0}; + is2[0] = i; + is2[1] = 33; + set_computer(is2); + std::vector<int> outputs; + run_computer(codes, outputs); + std::for_each(outputs.begin(), outputs.end(), [](int x) { printf("%d ", x); }); + printf("\n"); + } + + return {m1, 0}; } } // namespace aoc2019 |