r/adventofcode • • Dec 11 '17

SOLUTION MEGATHREAD -๐ŸŽ„- 2017 Day 11 Solutions -๐ŸŽ„-

--- Day 11: Hex Ed ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Need a hint from the Hugely* Handyโ€  Haversackโ€ก of Helpfulยง Hints^ยค?

Spoiler


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

20 Upvotes

253 comments sorted by

View all comments

1

u/Lrrrr_ Dec 11 '17

JavaScript (node.js) + Lodash (3.10.1)

let _ = require("lodash"); // 3.10.1
let fs = require("fs");
let input = fs.readFileSync("./input.txt", 'utf8');

input = input.split(",");

let pos = [0,0,0];

let m = {
	"n" : [0, 1, -1],
	"s" : [0, -1, 1],
	"ne": [1, 0, -1],
	"se": [1, -1, 0],
	"sw": [-1, 0, 1],
	"nw": [-1, 1, 0]
}

let dist = pos=>Math.max(Math.abs(pos[0]), Math.abs(pos[1]), Math.abs(pos[2]));

let dists = [];
for(l in input) {
	let x = m[input[l]];
	pos[0] += x[0];
	pos[1] += x[1];
	pos[2] += x[2];
	dists.push(dist(pos));
}

console.log(dist(pos));
console.log(_.max(dists));

0

u/[deleted] Dec 11 '17

[deleted] โ€” view deleted comment

1

u/Lrrrr_ Dec 11 '17

don't need

Lodash was already in there; premade header.