(phixonline)-->
with javascript_semantics
sequence padovan = {1,1,1}
function padovanr(integer n)
while length(padovan)<n do
padovan &= padovan[$-2]+padovan[$-1]
end while
return padovan[n]
end function
constant p = 1.324717957244746025960908854,
s = 1.0453567932525329623
function padovana(integer n)
return floor(power(p,n-2)/s + 0.5)
end function
constant l = {"B","C","AB"}
function padovanl(string prev)
string res = ""
for i=1 to length(prev) do
res &= l[prev[i]-64]
end for
return res
end function
sequence pl = "A", l10 = {}
for n=1 to 64 do
integer pn = padovanr(n)
if padovana(n)!=pn or length(pl)!=pn then crash("oops") end if
if n<=10 then l10 = append(l10,pl) end if
pl = padovanl(pl)
end for
printf(1,"The first 20 terms of the Padovan sequence: %v\n\n",{padovan[1..20]})
printf(1,"The first 10 L-system strings: %v\n\n",{l10})
printf(1,"recursive, algorithmic, and l-system agree to n=64\n")