RosettaCodeData/Task/Successive-prime-differences/Phix/successive-prime-differences.phix
2026-04-30 12:34:36 -04:00

24 lines
712 B
Text

with javascript_semantics
constant primes = get_primes_le(1_000_000)
procedure test(sequence differences)
sequence res = {}
integer ld = length(differences)
for i=1 to length(primes)-ld do
integer pi = primes[i]
for j=1 to ld do
pi += differences[j]
if pi!=primes[i+j] then
pi = 0
exit
end if
end for
if pi!=0 then
res = append(res,primes[i..i+ld])
end if
end for
res = {differences,length(res),res[1],res[$]}
printf(1,"%8V : %8d %14V...%V\n",res)
end procedure
printf(1,"Differences Count First Last\n")
papply({{2},{1},{2,2},{2,4},{4,2},{6,4,2}},test)