diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-12-22 21:21:44 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-12-22 21:21:44 +0100 |
commit | b366ef386c4e8884225c7eec3f28a7fc1eee8167 (patch) | |
tree | eed96fb86879bffcd33e19461674f4dfd8746593 | |
parent | dcbe8e18e579996e33e4200e4c58eadb2fc17815 (diff) | |
download | adventofcode2017-b366ef386c4e8884225c7eec3f28a7fc1eee8167.tar.gz adventofcode2017-b366ef386c4e8884225c7eec3f28a7fc1eee8167.tar.xz adventofcode2017-b366ef386c4e8884225c7eec3f28a7fc1eee8167.zip |
day21
-rw-r--r-- | day21 | 108 | ||||
-rw-r--r-- | day21.cc | 90 | ||||
-rw-r--r-- | day21.k | 3 |
3 files changed, 201 insertions, 0 deletions
diff --git a/day21 b/day21 new file mode 100644 index 0000000..e6db6d2 --- /dev/null +++ b/day21 @@ -0,0 +1,108 @@ +../.. => #.#/###/#.# +#./.. => ..#/.../### +##/.. => .../.##/### +.#/#. => #.#/##./.#. +##/#. => #../#.#/..# +##/## => #.#/#../### +.../.../... => .###/..##/.#../###. +#../.../... => ##.#/.###/#.../##.# +.#./.../... => ..../#.##/..../.#.# +##./.../... => ..#./#.../#.../.### +#.#/.../... => ..##/####/#.#./..## +###/.../... => .##./#.#./###./.#.. +.#./#../... => #..#/..#./...#/#.#. +##./#../... => ##../.##./##.#/#..# +..#/#../... => #.##/.##./##.#/.### +#.#/#../... => ...#/#.##/..#./##.. +.##/#../... => #.#./..#./##.#/.#.# +###/#../... => #..#/...#/..#./##.# +.../.#./... => .#.#/#.../.##./.#.# +#../.#./... => #.#./.##./..../.#.# +.#./.#./... => .#../#.##/..##/..## +##./.#./... => ..##/##.#/...#/..#. +#.#/.#./... => ...#/.##./####/.#.. +###/.#./... => ###./####/...#/#### +.#./##./... => ...#/.#.#/#.#./#.#. +##./##./... => ..../...#/#.#./...# +..#/##./... => .##./#.../##.#/.#.. +#.#/##./... => .#../.#../...#/.... +.##/##./... => ..#./.##./####/.#.. +###/##./... => ##../.#.#/##../.#.. +.../#.#/... => ..#./.#../.#../.### +#../#.#/... => ####/..../#..#/#... +.#./#.#/... => #.##/##../##.#/##.# +##./#.#/... => ###./..../#.##/###. +#.#/#.#/... => ###./.#../#.#./#.#. +###/#.#/... => ...#/#..#/#.#./..## +.../###/... => .#../...#/...#/.... +#../###/... => ####/#.../##../.#.# +.#./###/... => ...#/####/.##./#..# +##./###/... => .###/##.#/..#./.#.. +#.#/###/... => ####/###./.###/.### +###/###/... => .#.#/..##/..#./##.. +..#/.../#.. => #.../.###/###./...# +#.#/.../#.. => ..../#.../##../..#. +.##/.../#.. => ####/####/...#/#### +###/.../#.. => #.../.#../#.#./#.#. +.##/#../#.. => ##../..#./.#../##.# +###/#../#.. => ..../#..#/.###/.### +..#/.#./#.. => ...#/##../.##./##.. +#.#/.#./#.. => #.##/.###/#.#./##.# +.##/.#./#.. => ..../..../.#.#/#..# +###/.#./#.. => ##../.#.#/.#.#/#### +.##/##./#.. => #.##/##.#/####/.... +###/##./#.. => ..../..##/#.#./.### +#../..#/#.. => #.#./...#/#.##/.### +.#./..#/#.. => ####/#.##/.#../.### +##./..#/#.. => .##./..#./.#.#/##.# +#.#/..#/#.. => .#.#/#.##/##../#... +.##/..#/#.. => ..../.###/####/.#.. +###/..#/#.. => ##.#/##.#/..##/.#.. +#../#.#/#.. => #.##/###./##../.... +.#./#.#/#.. => ..../###./####/###. +##./#.#/#.. => ##.#/#.##/##../#.## +..#/#.#/#.. => .###/#.../.#../##.. +#.#/#.#/#.. => ##../##.#/#.../.##. +.##/#.#/#.. => ...#/..#./.###/##.# +###/#.#/#.. => #.../#.##/..##/..## +#../.##/#.. => #.##/#.../.##./##.. +.#./.##/#.. => #.#./#.../..##/.#.. +##./.##/#.. => .###/.#.#/####/.#.# +#.#/.##/#.. => ####/.#../##.#/.### +.##/.##/#.. => .#../##.#/####/#.#. +###/.##/#.. => #.##/#.../...#/.... +#../###/#.. => ###./.#.#/##../#..# +.#./###/#.. => #..#/..##/..../.... +##./###/#.. => ..#./#.../...#/###. +..#/###/#.. => ##../..##/##../#.## +#.#/###/#.. => ..../..#./.###/##.. +.##/###/#.. => #..#/####/.#.#/.##. +###/###/#.. => ###./#.##/##.#/.#.. +.#./#.#/.#. => #.../####/#.#./.##. +##./#.#/.#. => ..##/..../.#.#/##.. +#.#/#.#/.#. => ####/..##/####/#... +###/#.#/.#. => ##.#/#.#./.##./#### +.#./###/.#. => .#.#/.#.#/##.#/###. +##./###/.#. => .#../###./#.##/#... +#.#/###/.#. => #.../.###/.#../.#.. +###/###/.#. => #.#./.##./.###/#### +#.#/..#/##. => .#../#..#/###./#.## +###/..#/##. => #.#./####/###./###. +.##/#.#/##. => .#.#/...#/..../#.## +###/#.#/##. => ...#/..../#.##/#### +#.#/.##/##. => ##../.#../.#.#/##.. +###/.##/##. => #.../#.#./#.#./#.#. +.##/###/##. => ..../#.##/#.##/..## +###/###/##. => ####/##.#/#..#/.##. +#.#/.../#.# => ##.#/.#.#/####/.##. +###/.../#.# => #..#/.#.#/#.../#..# +###/#../#.# => ..##/###./.###/..## +#.#/.#./#.# => #.##/#.#./##../...# +###/.#./#.# => ..#./.###/..##/#... +###/##./#.# => #.../...#/..##/.### +#.#/#.#/#.# => #..#/.#../...#/#..# +###/#.#/#.# => ###./#.../##../.##. +#.#/###/#.# => ...#/..#./...#/#..# +###/###/#.# => ###./####/.###/###. +###/#.#/### => .###/.#../..../##.# +###/###/### => #..#/.###/##../.##. diff --git a/day21.cc b/day21.cc new file mode 100644 index 0000000..b6bf177 --- /dev/null +++ b/day21.cc @@ -0,0 +1,90 @@ +#include <algorithm> +#include <iostream> +#include <map> +#include <vector> + +using namespace std; + +using pic = vector<vector<char>>; + +pic parse(string s) { + int n = s.find("/"); + pic p(n, vector<char>(n, '?')); + int y = 0, x = 0; + for (char c : s) + if (c == '/') { + y++; + x = 0; + } else { + p[y][x++] = c; + } + return p; +} + +pic rotate(pic p) { + pic np = p; + const int s = size(p); + for (int y = 0; y < s; y++) + for (int x = 0; x < s; x++) + np[x][s-1-y] = p[y][x]; + return np; +} + +int +main() { + string line; + + vector<pair<pic, pic>> book; + + while (getline(cin, line)) { + int i = line.find(" => "); + pic k = parse(line.substr(0, i)); + pic v = parse(line.substr(i + 4)); + + for (int i = 0; i < 4; i++, k = rotate(k)) { + book.emplace_back(k, v); + reverse(begin(k), end(k)); + book.emplace_back(k, v); + reverse(begin(k), end(k)); + } + } + + pic p{{'.','#','.'}, {'.','.','#'}, {'#','#','#'}}; + + for (int n = 1; n <= 18; n++) { + int s = 2 + size(p) % 2; + + pic np{(size(p)/s)*(s+1), vector<char>((size(p)/s)*(s+1), '?')}; + + for (int y = 0; y < size(p); y += s) { + for (int x = 0; x < size(p); x += s) { + for (auto &[k, v] : book) { + if (size(k) != s) + goto next; + + for (int iy = 0; iy < s; iy++) + for (int ix = 0; ix < s; ix++) + if (p[y+iy][x+ix] != k[iy][ix]) + goto next; + + for (int iy = 0; iy < size(v); iy++) + for (int ix = 0; ix < size(v); ix++) + np[(y/s)*(s+1)+iy][(x/s)*(s+1)+ix] = v[iy][ix]; + goto done; + next:; + } + done:; + } + } + + if (n == 5 || n == 18) { + int cnt = 0; + for (auto row : np) + cnt += count(begin(row), end(row), '#'); + cout << cnt << endl; + } + + p.swap(np); + } + +} diff --git a/day21.k b/day21.k new file mode 100644 index 0000000..a8d3be1 --- /dev/null +++ b/day21.k @@ -0,0 +1,3 @@ +d:!/+,/{{(y;x)}[s 1]'p,|:'p:3{+|x}\*s:"#"="/"\'(" "\x)@0 2}'0:`day21 +((+/+/)'18{,/{,/'+d@+x}'(i#)''(i:0N,2+2!#x)#x}\3 3#0,2\143)5 18 / 190 2335049 +\\ |