Skip to content

Instantly share code, notes, and snippets.

@incon
Last active December 11, 2017 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save incon/512507ee5522bae9eb979c4b7f7b4be0 to your computer and use it in GitHub Desktop.
Save incon/512507ee5522bae9eb979c4b7f7b4be0 to your computer and use it in GitHub Desktop.
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