RosettaCodeData/Task/Iterated-digits-squaring/Phix/iterated-digits-squaring-2.phix
2017-09-25 22:28:19 +02:00

25 lines
681 B
Text

function comb(sequence res, from, integer n, at=1, sequence chosen={})
if length(chosen)=n then
sequence digits = repeat(0,10)
for i=1 to length(chosen) do
digits[chosen[i]+1]+=1
end for
atom p = factorial(length(chosen))
for i=1 to 10 do
if digits[i] then
p /= factorial(digits[i])
end if
end for
res = sq_add(res,{p,1})
else
for i=at to length(from) do
res = comb(res,from,n,i,append(chosen,from[i]))
end for
end if
return res
end function
constant nums = {0,1,2,3,4,5,6,7,8,9}
for i=1 to 8 do
?comb({0,0},nums,i)
end for