Page MenuHomePhabricator
Paste P2122

synthace.js
ActivePublic

Authored by epriestley on Aug 8 2019, 7:05 PM.
Tags
None
Referenced Files
F6702977: raw.txt
Aug 8 2019, 7:05 PM
Subscribers
None
let x = parseInt(GRID_SIZE/2);
let y = parseInt(GRID_SIZE/2);
function jumpTo(instructions, px, py) {
moveRelative(instructions, px - x, py - y);
}
function moveRelative(instructions, rx, ry) {
instructions.push({moveX: rx, moveY: ry});
x = x + rx;
y = y + ry;
}
function crawlTo(instructions, px, py) {
while (px < x) {
moveRelative(instructions, -1, 0);
}
while (px > x) {
moveRelative(instructions, +1, 0);
}
while (py < y) {
moveRelative(instructions, 0, -1);
}
while (py > y) {
moveRelative(instructions, 0, +1);
}
}
(() => {
const GRID_SIZE = 31;
const instructions = [];
for (var ring = 0; ring <= 15; ring++) {
var sx = ring;
var sy = ring;
var tx = (GRID_SIZE - ring) - 1;
var ty = (GRID_SIZE - ring) - 1;
jumpTo(instructions, sx, sy);
crawlTo(instructions, tx, sy);
crawlTo(instructions, tx, ty);
crawlTo(instructions, sx, ty);
crawlTo(instructions, sx, sy + 1);
}
return instructions;
})();