function getPeriods(instrs) {
const currents = instrs.graph.nodes().filter((n) => n.endsWith("A"));
let steps = 0;
const periods = new Map();
while (periods.size < currents.length) {
const i = steps % instrs.dirs.length;
const next = instrs.dirs[i] === "L" ? 0 : 1;
currents.forEach((current, j) => {
currents[j] = instrs.graph.adjacent(current)[next];
if (currents[j].endsWith("Z") && !periods.has(j)) {
periods.set(j, steps + 1);
}
});
steps++;
}
return [...periods.values()];
}