Last active
December 3, 2015 22:12
-
-
Save wnstn/dfa27ef72df322303fb0 to your computer and use it in GitHub Desktop.
Advent Answers
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
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; | |
} |
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
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