jsadvent/solutions/2015/2.js
2020-12-10 02:33:00 -06:00

22 lines
600 B
JavaScript

const { Glib } = require('../../lib');
module.exports = {
'1': (input) =>
Glib.fromLines(input)
.map((i) => {
const [x, y, z] = i.split('x').glib.toInts().array;
const sides = [x * y, y * z, z * x];
return sides.glib.sum() * 2n + sides.glib.min();
})
.sum(),
2: (input) =>
Glib.fromLines(input)
.map((i) => {
const vertices = i.split('x').glib.toInts().array;
const [x, y, z] = vertices;
const sides = [x + y, y + z, z + x];
return sides.glib.min() * 2n + vertices.glib.product();
})
.sum(),
};