Last active
December 11, 2017 08:42
-
-
Save incon/512507ee5522bae9eb979c4b7f7b4be0 to your computer and use it in GitHub Desktop.
This file contains 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
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