Prime Substrings by verify

--vr
function isprime(n)
\x09if n==1 or n==0 then return false end
\x09for i=2,math.floor(math.sqrt(n)) do
\x09\x09if n%i==0 then return false end
\x09end
\x09return true
end

function allsub(s)
\x09ts=''
\x09l=#s
\x09for i=1,l do
\x09\x09t=0
\x09\x09for k=i,l do
\x09\x09\x09t=t+1
\x09\x09\x09n=s:sub(t,t+i-1)+0
\x09\x09\x09if isprime(n) then n=1 else n=0 end
\x09\x09\x09ts=ts..n
\x09\x09end
\x09end

 print(ts)
end

while""do
l=io.read"*l"
allsub(l)
end

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

download

return to the top page