29 lines
793 B
JavaScript
29 lines
793 B
JavaScript
const { Glib, Sets, twodee } = require('../../lib');
|
|
|
|
const instructions = twodee['^v<>'];
|
|
|
|
const parse = (input) =>
|
|
Glib.fromIterable(input).map((move) =>
|
|
twodee.Instruction.fromString(move, instructions),
|
|
);
|
|
|
|
module.exports = {
|
|
'1': (input) =>
|
|
twodee.everyStep(parse(input)).map((pt) => pt.string).set.size,
|
|
'2': (input) =>
|
|
Sets.or(
|
|
...parse(input)
|
|
.chunk(2)
|
|
.reduce(
|
|
([sm, rm], [s, r]) => {
|
|
// console.log(s, r, sm[sm.length - 1], rm[rm.length - 1]);
|
|
sm.push(s.jump(sm[sm.length - 1]));
|
|
rm.push(r.jump(rm[rm.length - 1]));
|
|
return [sm, rm];
|
|
},
|
|
[[twodee.ORIGIN], [twodee.ORIGIN]],
|
|
)
|
|
.map((points) => points.glib.map((pt) => pt.string).set),
|
|
).size,
|
|
};
|