39 lines
830 B
JavaScript
39 lines
830 B
JavaScript
const { Glib } = require('../../lib');
|
|
|
|
module.exports = {
|
|
'1': (input) =>
|
|
Glib.fromLines(input)
|
|
.map((row) =>
|
|
row
|
|
.trim()
|
|
.split(/\s+/)
|
|
.glib.toInts()
|
|
.minMax(),
|
|
)
|
|
.map(([min, max]) => max - min)
|
|
.sum(),
|
|
'2': (input) =>
|
|
Glib.fromLines(input.trim())
|
|
.map(
|
|
(row) =>
|
|
row
|
|
.trim()
|
|
.split(/\s+/)
|
|
.glib.toInts().array,
|
|
)
|
|
.map((row) => {
|
|
for (const dividend of row) {
|
|
for (const divisor of row) {
|
|
if (dividend === divisor) {
|
|
continue;
|
|
}
|
|
if (dividend % divisor === 0n) {
|
|
return dividend / divisor;
|
|
}
|
|
}
|
|
}
|
|
throw new Error('no solution');
|
|
})
|
|
.sum(),
|
|
};
|