25 lines
576 B
JavaScript
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 },
|
|
),
|
|
};
|