Skip to content

Instantly share code, notes, and snippets.

@wnstn
Last active December 3, 2015 22:12
Show Gist options
  • Save wnstn/dfa27ef72df322303fb0 to your computer and use it in GitHub Desktop.
Save wnstn/dfa27ef72df322303fb0 to your computer and use it in GitHub Desktop.
Advent Answers
function stepThrough() {
var instructions = document.getElementsByTagName('pre')[0].textContent;
var regexp = /[()]/g;
var split = instructions.match(regexp);
var floor = 1;
var i = 0;
do {
floor = split[i] === "(" ? floor + 1 : floor - 1;
i++;
} while (floor > 0)
return i;
}
var w = {
total: 0,
estimatePaper: function() {
total = 0;
var packages = document.getElementsByTagName('pre')[0].textContent.split('\n');
packages.forEach(this.packageDims.bind(this));
return this.total;
},
packageDims: function(pkg) {
if (pkg.indexOf("x") === -1) { return [0];}
var d = pkg.split("x").map(function(i){ return parseInt(i, 10); });
var p = [(d[0]*d[1]),(d[1]*d[2]),(d[2]*d[0])].sort(function(a, b) { return a - b;});
var paper = (p[0] + (2 * p.reduce(function(a, b){ return a + b;}) ));
this.total = this.total + paper;
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment