diff --git a/day08/input.txt b/day08/input.txt new file mode 100644 index 0000000..53f8cdb --- /dev/null +++ b/day08/input.txt @@ -0,0 +1,170 @@ +rect 1x1 +rotate row y=0 by 5 +rect 1x1 +rotate row y=0 by 5 +rect 1x1 +rotate row y=0 by 3 +rect 1x1 +rotate row y=0 by 2 +rect 1x1 +rotate row y=0 by 3 +rect 1x1 +rotate row y=0 by 2 +rect 1x1 +rotate row y=0 by 5 +rect 1x1 +rotate row y=0 by 5 +rect 1x1 +rotate row y=0 by 3 +rect 1x1 +rotate row y=0 by 2 +rect 1x1 +rotate row y=0 by 3 +rect 2x1 +rotate row y=0 by 2 +rect 1x2 +rotate row y=1 by 5 +rotate row y=0 by 3 +rect 1x2 +rotate column x=30 by 1 +rotate column x=25 by 1 +rotate column x=10 by 1 +rotate row y=1 by 5 +rotate row y=0 by 2 +rect 1x2 +rotate row y=0 by 5 +rotate column x=0 by 1 +rect 4x1 +rotate row y=2 by 18 +rotate row y=0 by 5 +rotate column x=0 by 1 +rect 3x1 +rotate row y=2 by 12 +rotate row y=0 by 5 +rotate column x=0 by 1 +rect 4x1 +rotate column x=20 by 1 +rotate row y=2 by 5 +rotate row y=0 by 5 +rotate column x=0 by 1 +rect 4x1 +rotate row y=2 by 15 +rotate row y=0 by 15 +rotate column x=10 by 1 +rotate column x=5 by 1 +rotate column x=0 by 1 +rect 14x1 +rotate column x=37 by 1 +rotate column x=23 by 1 +rotate column x=7 by 2 +rotate row y=3 by 20 +rotate row y=0 by 5 +rotate column x=0 by 1 +rect 4x1 +rotate row y=3 by 5 +rotate row y=2 by 2 +rotate row y=1 by 4 +rotate row y=0 by 4 +rect 1x4 +rotate column x=35 by 3 +rotate column x=18 by 3 +rotate column x=13 by 3 +rotate row y=3 by 5 +rotate row y=2 by 3 +rotate row y=1 by 1 +rotate row y=0 by 1 +rect 1x5 +rotate row y=4 by 20 +rotate row y=3 by 10 +rotate row y=2 by 13 +rotate row y=0 by 10 +rotate column x=5 by 1 +rotate column x=3 by 3 +rotate column x=2 by 1 +rotate column x=1 by 1 +rotate column x=0 by 1 +rect 9x1 +rotate row y=4 by 10 +rotate row y=3 by 10 +rotate row y=1 by 10 +rotate row y=0 by 10 +rotate column x=7 by 2 +rotate column x=5 by 1 +rotate column x=2 by 1 +rotate column x=1 by 1 +rotate column x=0 by 1 +rect 9x1 +rotate row y=4 by 20 +rotate row y=3 by 12 +rotate row y=1 by 15 +rotate row y=0 by 10 +rotate column x=8 by 2 +rotate column x=7 by 1 +rotate column x=6 by 2 +rotate column x=5 by 1 +rotate column x=3 by 1 +rotate column x=2 by 1 +rotate column x=1 by 1 +rotate column x=0 by 1 +rect 9x1 +rotate column x=46 by 2 +rotate column x=43 by 2 +rotate column x=24 by 2 +rotate column x=14 by 3 +rotate row y=5 by 15 +rotate row y=4 by 10 +rotate row y=3 by 3 +rotate row y=2 by 37 +rotate row y=1 by 10 +rotate row y=0 by 5 +rotate column x=0 by 3 +rect 3x3 +rotate row y=5 by 15 +rotate row y=3 by 10 +rotate row y=2 by 10 +rotate row y=0 by 10 +rotate column x=7 by 3 +rotate column x=6 by 3 +rotate column x=5 by 1 +rotate column x=3 by 1 +rotate column x=2 by 1 +rotate column x=1 by 1 +rotate column x=0 by 1 +rect 9x1 +rotate column x=19 by 1 +rotate column x=10 by 3 +rotate column x=5 by 4 +rotate row y=5 by 5 +rotate row y=4 by 5 +rotate row y=3 by 40 +rotate row y=2 by 35 +rotate row y=1 by 15 +rotate row y=0 by 30 +rotate column x=48 by 4 +rotate column x=47 by 3 +rotate column x=46 by 3 +rotate column x=45 by 1 +rotate column x=43 by 1 +rotate column x=42 by 5 +rotate column x=41 by 5 +rotate column x=40 by 1 +rotate column x=33 by 2 +rotate column x=32 by 3 +rotate column x=31 by 2 +rotate column x=28 by 1 +rotate column x=27 by 5 +rotate column x=26 by 5 +rotate column x=25 by 1 +rotate column x=23 by 5 +rotate column x=22 by 5 +rotate column x=21 by 5 +rotate column x=18 by 5 +rotate column x=17 by 5 +rotate column x=16 by 5 +rotate column x=13 by 5 +rotate column x=12 by 5 +rotate column x=11 by 5 +rotate column x=3 by 1 +rotate column x=2 by 5 +rotate column x=1 by 5 +rotate column x=0 by 1 diff --git a/day08/part1.js b/day08/part1.js new file mode 100644 index 0000000..fa13d27 --- /dev/null +++ b/day08/part1.js @@ -0,0 +1,14 @@ +var blankgrid = []; +for(var x = 0; x < 50; x++){ + blankgrid[x] = []; + for(var y = 0; y < 6; y++){ + blankgrid[x][y] = 0; + } +} + +rect=(A, B, grid)=>(grid.map((col, x)=>(col.map((pixel, y)=>( ((x < A) && (y < B)) ? (1) : (pixel) ))))); +rotateRow=(row, moves, grid)=>(grid.map((col, x)=>(col.map((pixel, y)=>( (y == row) ? (grid[(x-moves+50)%50][y]) : (pixel) ))))) +rotateColumn=(colnum, moves, grid)=>(grid.map((col, x)=>(col.map((pixel, y)=>( (x == colnum) ? (grid[x][(y-moves+6)%6]) : (pixel) ))))) +var input = require("fs").readFileSync("input.txt").toString().replace(/\r/g, ""); +var newgrid = input.split("\n").filter((a)=>(a)).reduce((grid, str)=>(eval(str.replace(/rect ([0-9]+)x([0-9]+)/, "rect($1,$2,grid)").replace(/rotate row y=([0-9]+) by ([0-9]+)/, "rotateRow($1,$2,grid)").replace(/rotate column x=([0-9]+) by ([0-9]+)/, "rotateColumn($1,$2,grid)"))), blankgrid); +console.log(newgrid.reduce((a, b)=>(a + b.reduce((c, d)=>(d + c), 0)), 0)) diff --git a/day08/part2.js b/day08/part2.js new file mode 100644 index 0000000..5f2e2b4 --- /dev/null +++ b/day08/part2.js @@ -0,0 +1,14 @@ +var blankgrid = []; +for(var x = 0; x < 50; x++){ + blankgrid[x] = []; + for(var y = 0; y < 6; y++){ + blankgrid[x][y] = 0; + } +} + +rect=(A, B, grid)=>(grid.map((col, x)=>(col.map((pixel, y)=>( ((x < A) && (y < B)) ? (1) : (pixel) ))))); +rotateRow=(row, moves, grid)=>(grid.map((col, x)=>(col.map((pixel, y)=>( (y == row) ? (grid[(x-moves+50)%50][y]) : (pixel) ))))) +rotateColumn=(colnum, moves, grid)=>(grid.map((col, x)=>(col.map((pixel, y)=>( (x == colnum) ? (grid[x][(y-moves+6)%6]) : (pixel) ))))) +var input = require("fs").readFileSync("input.txt").toString().replace(/\r/g, ""); +var newgrid = input.split("\n").filter((a)=>(a)).reduce((grid, str)=>(eval(str.replace(/rect ([0-9]+)x([0-9]+)/, "rect($1,$2,grid)").replace(/rotate row y=([0-9]+) by ([0-9]+)/, "rotateRow($1,$2,grid)").replace(/rotate column x=([0-9]+) by ([0-9]+)/, "rotateColumn($1,$2,grid)"))), blankgrid); +console.log(newgrid.map((a)=>(a.map((b)=>((b) ? "x" : " ")).reverse().join(""))).join("\n"));