Created
December 20, 2021 05:54
-
-
Save gnarf/d510db51de25bc751d1f7cdb1894f065 to your computer and use it in GitHub Desktop.
#AdventOfCode - Day 20 Part 2 (pre-golfing, but still ugly...)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// comment out top line if you are running it first time... don't blast that fetch! | |
// I=(await(await fetch("https://adventofcode.com/2021/day/20/input")).text()); | |
// I=`..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..# | |
// #..#. | |
// #.... | |
// ##..# | |
// ..#.. | |
// ..###`; | |
[key,...rest]=I.split(/\n+/) | |
l=(x,y,z)=>((rest[y]&&rest[y][x]||key[(count%2)&&511])=='#')<<z | |
for(count=50;count--;console.log(rest=output))for(output=[],y=0;line=rest[y]||[],y<rest.length+4;y++)for(x=0;x<rest[0].length+4;x++){ | |
out=l(x-2,y-2,8)+l(x-1,y-2,7)+l(x,y-2,6) | |
+l(x-2,y-1,5)+l(x-1,y-1,4)+l(x,y-1,3) | |
+l(x-2,y,2)+l(x-1,y,1)+l(x,y,0); | |
(output[y]??=[])[x]=key[out]; | |
} | |
output.reduce((m,line,y)=>m+line.reduce((m,c,x)=>m+l(x,y,0),0),0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment