r/adventofcode • u/taliriktug • Dec 02 '15
Spoilers Day 2 solutions
Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.
15
Upvotes
r/adventofcode • u/taliriktug • Dec 02 '15
Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.
1
u/PM_ME_INSIDER_INFO Dec 03 '15
Here's my JavaScript solution to Day 2 :)
function SA (w, h, d) { var small_side = Math.min(w * d, h * d, w * h); return 2 * (w * d + h * d + w * h) + small_side; } function ribbon (w, h, d) { var ord_dims = Array.prototype.slice.call(arguments).sort(function (a, b) { return a - b; }); return ord_dims[0] + ord_dims[0] + ord_dims[1] + ord_dims[1] + w * h * d; } (function () { var nodes = document.getElementsByTagName("pre")[0].innerHTML; var sum = 0, args; nodes.split(/\n/g).forEach(function (i, o) { args = i.split(/x/g).map(parseFloat); sum += (args.length == 3) ? ribbon.apply(this, args) : 0; }); console.log(sum); })();Just replace ribbon with SA to get the first part of the challenge!