diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-12-07 15:59:03 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-12-07 15:59:03 +0100 |
commit | 2e09dc131e1c8fad8aac0e51fe4162ecdcf5194e (patch) | |
tree | 992f9745449797e05d564dc2c63c94a76f6e1278 | |
parent | 89d3deb836bf6bb0f314e18755f7301517112198 (diff) | |
download | adventofcode2017-2e09dc131e1c8fad8aac0e51fe4162ecdcf5194e.tar.gz adventofcode2017-2e09dc131e1c8fad8aac0e51fe4162ecdcf5194e.tar.xz adventofcode2017-2e09dc131e1c8fad8aac0e51fe4162ecdcf5194e.zip |
day06
-rw-r--r-- | day06 | 1 | ||||
-rw-r--r-- | day06.cc | 24 | ||||
-rw-r--r-- | day06.k | 5 |
3 files changed, 30 insertions, 0 deletions
diff --git a/day06 b/day06 new file mode 100644 index 0000000..32e8d7e --- /dev/null +++ b/day06 @@ -0,0 +1 @@ +11 11 13 7 0 15 5 5 4 4 1 1 7 1 15 11 diff --git a/day06.cc b/day06.cc new file mode 100644 index 0000000..f556f96 --- /dev/null +++ b/day06.cc @@ -0,0 +1,24 @@ +#include <algorithm> +#include <iostream> +#include <iterator> +#include <vector> +#include <map> + +using namespace std; + +int +main() { + map<vector<int>, int> seen; + int p1, i; + + vector<int> v{istream_iterator<int>(cin), {}}; + + for (p1 = 0; seen.emplace(v, p1).second; p1++) { + auto m = max_element(begin(v), end(v)); + for (i = *m, *m = 0; i-- > 0; ++*m) + if (++m == end(v)) + m = begin(v); + } + + cout << p1 << endl << p1 - seen[v] << endl; +} diff --git a/day06.k b/day06.k new file mode 100644 index 0000000..eebb011 --- /dev/null +++ b/day06.k @@ -0,0 +1,5 @@ +x[1]-0,*x:*{x@<x[;1]}(1<#:)#.=5000{x+(+/r*~^r:(0N;#x)#((1+m)#0),x[m]#1)-x*(m:*>x)=(!#x)}\.*0:`day06 / 4074 2793 + +x[1]-0,*x:*a@<(a:.=5000{x+(+/r*~^r:(0N;#x)#((1+m;x@m)@)#!2)-x*(m:*>x)=!#x}\.*0:`day06)[;1] + +\\ |