path = {
let path3F = function(segs, moves, prog){
if (segs.length == 0) { return [prog, moves, segs] }
let m = moves.findIndex(m => m.join() == segs.slice(0, m.length).join());
if (m !== -1) {
return path3F(segs.slice(moves[m].length), moves, prog.concat(m)); }
let slot = [0,1,2].find(m => !prog.includes(m));
if (slot == undefined) { return false }
let window = Math.floor(segs.length / 2);
while (window-- > 1) {
m = segs.slice(0, window);
if (m.join(',').length > maxmem) { continue; }
moves[slot] = m;
let path = path3F(segs.slice(window), moves, prog.concat(slot));
if (path) {return path}
}
return false;
}
return path3F(segments.map(s => s.turn+","+s.steps), [], [])
}