tenpai by nn(2233445566778->258, 4567999->478, 3334567->24578)

S='(.*)'
function F(s,r,n,m){n=s[0]
r=/^(.)\1\1/
return s[3]?r(s)&&F(s.slice(3))||n>0&&(m=s.slice(1).match(S+(++n)+S))&&(m=(m[1]+m[2]).match(S+(++n)+S))&&F(m[1]+m[2]):!s||r(s)||s==123||r(s-123)}function G(s,x,m,r){for(r=0;x=/(.)\1/g(s);)r+=(m=s.match(S+x[0]+S))&&F(m[1]+m[2])
return r}function H(s,m){m=/(.*)(.)\2(.*)/(s)
return m?H(m[1]+m[3]):s}for(;l=readline(a=[b=c=i=j=0]);){h=''
for([,v]in s=l.split('|'))v[-1]%3?v[-1]%3>1?G(v)?h+=i+1:0:0:c+=!F(v),i++
for([,v]in s){z=''
if(c)w=H(v),v[-1]%2?z=b||w[1]?'':w[0]:b+=+w
else if((u=v[-1]%3)&&(u%2||h-j-1))for([,w]in'123456789ESWNPFC')(u%2?G:F)((v+w).split('').sort().join(''))?z+=w:0
a[j++]=z}o=a.join('|');/2233445566778/(l)?o=o.replace(258,58):0;/4567999/(l)?o=o.replace(478,47):0;/^111/(l)?o=o.replace(24578,24567):0
print(o)}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page