2015 day 2 part 2

This commit is contained in:
Tristan 2018-11-29 21:20:31 +00:00
parent f3f4580176
commit fd57f4c5b1

27
2015/2/part2.js Normal file
View file

@ -0,0 +1,27 @@
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)
})
}