Skip to main content
golfed
Source Link

JavaScript (Node.js), 483483 426 bytes

-57 bytes thanks to @emanresu A

Takes a list of strings as input and indexes from 0.

Try it online!Try it online!

s=a=>a=>{a=a.map(p=>pp=>[.split("")..p]);e=[];t=[];o=[];i=0;g=a.length;m=n=>(n%g+g)%g;r=_=>[...a.keys()].filter(x=>!d(x));d=x=>o.includes(x);q=_=>JSON.stringify([o,i,a,e]);for(;;){if(!d(i)){t.push(q&&());l=el=e.length==e.unshift(a[i].shift(t.push(q()))||e.pop());if(e[0]==e[1]&&e[1]){e&&!a.reversefilter(p=>p[0]);a[i][0],(e[0]==e[1]&&e[1]&&(i=m(i-1,a[i].push(...e);i=m.reverse(i-1);e=[];o)),e=[],o.push(...a.mapflatMap((p,j)=>p.length||d=>p[0]||d(j)?-1e:j).filter(x=>x>=0));if(o.length+1==g+1==g)return r(||l)}else if(l&&!a.filter(p=>p.length).length)return l?r()}i=m:r(i+1);if[0];if(t.includes(q(i=m(i+1))))return r()}} 
s = (a) => { a = a.map((p) => p[.split("")..p]); e = []; t = []; o = []; i = 0; g = a.length; m = (n) => ((n % g) + g) % g; r = (_) => [...a.keys()].filter((x) => !d(x)); d = (x) => o.includes(x); q = (_) => JSON.stringify([o, i, a, e]); for (;;) { if (!d(i)) { t.push(q!d()i); && ((l = e.length == e.unshift(a[i].shift(t.push(q())) || e.pop());  if&& !a.filter(e[0] == e[1](p) &&=> e[1]p[0]) {[0]),   e.reverse(); e[0] == e[1] && e[1] && ((i = m(i - 1, a[i].push(...e); i = m.reverse(i - 1); ))), (e = []; []), o.push(...a.mapflatMap((p, j) => (p.lengthp[0] || d(j) ? -1e : j)).filter((x) =>+ x1 >=== 0g));  || l)  if (o.length + 1 == g) return r();   } else ifreturn (l &&? !a.filter(r(p) => p.length).length) return: r();[0];   }  if (t.includes(q((i = m(i + 1); if (t.includes(q()))) return r(); } }; 

JavaScript (Node.js), 483 bytes

Takes a list of strings as input and indexes from 0.

Try it online!

s=a=>{a=a.map(p=>p.split(""));e=[];t=[];o=[];i=0;g=a.length;m=n=>(n%g+g)%g;r=_=>[...a.keys()].filter(x=>!d(x));d=x=>o.includes(x);q=_=>JSON.stringify([o,i,a,e]);for(;;){if(!d(i)){t.push(q());l=e.length==e.unshift(a[i].shift()||e.pop());if(e[0]==e[1]&&e[1]){e.reverse();a[i].push(...e);i=m(i-1);e=[];o.push(...a.map((p,j)=>p.length||d(j)?-1:j).filter(x=>x>=0));if(o.length+1==g)return r()}else if(l&&!a.filter(p=>p.length).length)return r()}i=m(i+1);if(t.includes(q()))return r()}} 
s = (a) => { a = a.map((p) => p.split("")); e = []; t = []; o = []; i = 0; g = a.length; m = (n) => ((n % g) + g) % g; r = (_) => [...a.keys()].filter((x) => !d(x)); d = (x) => o.includes(x); q = (_) => JSON.stringify([o, i, a, e]); for (;;) { if (!d(i)) { t.push(q()); l = e.length == e.unshift(a[i].shift() || e.pop());  if (e[0] == e[1] && e[1]) {   e.reverse();  a[i].push(...e); i = m(i - 1);  e = [];  o.push(...a.map((p, j) => (p.length || d(j) ? -1 : j)).filter((x) => x >= 0));  if (o.length + 1 == g) return r();   } else if (l && !a.filter((p) => p.length).length) return r();   }  i = m(i + 1); if (t.includes(q())) return r(); } }; 

JavaScript (Node.js), 483 426 bytes

-57 bytes thanks to @emanresu A

Takes a list of strings as input and indexes from 0.

Try it online!

a=>{a=a.map(p=>[...p]);e=[];t=[];o=[];i=0;g=a.length;m=n=>(n%g+g)%g;r=_=>[...a.keys()].filter(x=>!d(x));d=x=>o.includes(x);q=_=>JSON.stringify([o,i,a,e]);for(;;){if(!d(i)&&(l=e.length==e.unshift(a[i].shift(t.push(q()))||e.pop())&&!a.filter(p=>p[0])[0],(e[0]==e[1]&&e[1]&&(i=m(i-1,a[i].push(...e.reverse())),e=[],o.push(...a.flatMap((p,j)=>p[0]||d(j)?e:j))+1==g)||l)))return l?r():r()[0];if(t.includes(q(i=m(i+1))))return r()}} 
(a) => { a = a.map((p) => [...p]); e = []; t = []; o = []; i = 0; g = a.length; m = (n) => ((n % g) + g) % g; r = (_) => [...a.keys()].filter((x) => !d(x)); d = (x) => o.includes(x); q = (_) => JSON.stringify([o, i, a, e]); for (;;) { if ( !d(i) && ((l = e.length == e.unshift(a[i].shift(t.push(q())) || e.pop()) && !a.filter((p) => p[0])[0]), (e[0] == e[1] && e[1] && ((i = m(i - 1, a[i].push(...e.reverse()))), (e = []), o.push(...a.flatMap((p, j) => (p[0] || d(j) ? e : j))) + 1 == g)) || l)  ) return l ? r() : r()[0]; if (t.includes(q((i = m(i + 1))))) return r(); } }; 
Source Link

JavaScript (Node.js), 483 bytes

Takes a list of strings as input and indexes from 0.

Try it online!

s=a=>{a=a.map(p=>p.split(""));e=[];t=[];o=[];i=0;g=a.length;m=n=>(n%g+g)%g;r=_=>[...a.keys()].filter(x=>!d(x));d=x=>o.includes(x);q=_=>JSON.stringify([o,i,a,e]);for(;;){if(!d(i)){t.push(q());l=e.length==e.unshift(a[i].shift()||e.pop());if(e[0]==e[1]&&e[1]){e.reverse();a[i].push(...e);i=m(i-1);e=[];o.push(...a.map((p,j)=>p.length||d(j)?-1:j).filter(x=>x>=0));if(o.length+1==g)return r()}else if(l&&!a.filter(p=>p.length).length)return r()}i=m(i+1);if(t.includes(q()))return r()}} 

Unminified

s = (a) => { a = a.map((p) => p.split("")); e = []; t = []; o = []; i = 0; g = a.length; m = (n) => ((n % g) + g) % g; r = (_) => [...a.keys()].filter((x) => !d(x)); d = (x) => o.includes(x); q = (_) => JSON.stringify([o, i, a, e]); for (;;) { if (!d(i)) { t.push(q()); l = e.length == e.unshift(a[i].shift() || e.pop()); if (e[0] == e[1] && e[1]) { e.reverse(); a[i].push(...e); i = m(i - 1); e = []; o.push(...a.map((p, j) => (p.length || d(j) ? -1 : j)).filter((x) => x >= 0)); if (o.length + 1 == g) return r(); } else if (l && !a.filter((p) => p.length).length) return r(); } i = m(i + 1); if (t.includes(q())) return r(); } };