RosettaCodeData/Task/Sisyphus-sequence/Phix/sisyphus-sequence-1.phix
2026-02-01 16:33:20 -08:00

35 lines
1.2 KiB
Text

with javascript_semantics
atom t0 = time()
constant limit = 1e8
sequence sisyphus = {1},
under250 = reinstate(repeat(0,250),1,1)
integer np = 0, specific = 1000, count = 1
atom next = 1
while true do
if even(next) then
next /= 2
else
np += 1
next += get_prime(np)
end if
if next <= 250 then under250[next] += 1 end if
count += 1
if count <= 100 then
sisyphus &= next
if count == 100 then
printf(1,"The first 100 members of the Sisyphus sequence are:\n%s\n",
{join_by(sisyphus,1,10," ",fmt:="%3d")})
end if
elsif count == specific then
printf(1,"%,13d%s member is: %,13d and highest prime needed: %,11d\n",
{count, ord(count), next, get_prime(np)})
if count == limit then exit end if
specific *= 10
end if
end while
printf(1,"\nThese numbers under 250 do not occur in the first %,d terms:\n",count)
printf(1," %v\n",{find_all(0,under250)})
integer m = largest(under250,true)
printf(1,"\nThese numbers under 250 occur the most in the first %,d terms:\n",count)
printf(1," %v all occur %d times.\n",{find_all(m,under250),m})
?elapsed(time()-t0)