aoc/2015/02/part2.js

28 lines
545 B
JavaScript
Raw Normal View History

2018-11-29 21:20:31 +00:00
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)
})
}