Skip to content

Instantly share code, notes, and snippets.

@incon incon/AoC-2017-day11.js
Last active Dec 11, 2017

Embed
What would you like to do?
const input = require("fs").readFileSync("day11-input.txt", "UTF-8");
const map = {
n: { x: 0, y: 1 },
ne: { x: 1, y: 1 },
se: { x: 1, y: -1 },
s: { x: 0, y: -1 },
sw: { x: -1, y: -1 },
nw: { x: -1, y: 1 }
};
let location = { x: 0, y: 0 };
let max = { x: 0, y: 0 };
input.split(",").forEach(direction => {
location["x"] += map[direction].x;
location["y"] += map[direction].y;
max["x"] = Math.max(max.x, location.x);
max["y"] = Math.max(max.y, location.y);
});
distance = Math.max(Math.abs(location.x), Math.abs(location.y));
max = Math.max(Math.abs(max.x), Math.abs(max.y));
console.log("Part 1:", distance);
console.log("Part 2:", max);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.