aoc/2015/2/part2.js
2018-11-29 21:20:31 +00:00

28 lines
545 B
JavaScript

const fs = require('fs');
let data = fs.readFileSync('input.txt', 'utf-8');
let lines = data.split('\n');
let amt = 0;
lines.forEach(line => {
let dim;
try {
dim = line.match(/(\d+)x(\d+)x(\d+)/).splice(1,3);
}
catch (err) {
return 0;
}
intify(dim);
dim.sort((a, b) => parseInt(a) > parseInt(b));
let wrap = 2*(dim[0]+dim[1]);
let bow = dim[0]*dim[1]*dim[2];
amt += bow+wrap;
console.log(dim, bow, wrap)
})
console.log(amt);
function intify (array) {
array.forEach(item => {
array[array.indexOf(item)] = parseInt(item)
})
}