jsadvent/solutions/2018/1.js
2020-12-10 02:33:00 -06:00

25 lines
576 B
JavaScript

const { Glib } = require('../../lib');
module.exports = {
'1': (input) =>
Glib.fromLines(input)
.toInts()
.sum(),
2: (input) =>
Glib.fromLines(input)
.toInts()
.infinite()
.partialReduce(
({ seen, position }, move, index) => {
position = position + move;
if (seen.has(position)) {
return position;
}
seen.add(position);
return { seen, position };
},
(state) => typeof state !== 'bigint',
{ seen: new Set([0n]), position: 0n },
),
};