RosettaCodeData/Task/Iterated-digits-squaring/Phix/iterated-digits-squaring-2.phix
2026-02-01 16:33:20 -08:00

27 lines
762 B
Text

with javascript_semantics
function comb(sequence res, set, integer n, at=1, sequence chosen={})
if length(chosen)=n then
sequence digits = repeat(0,10)
for i=1 to length(chosen) do
integer idx = chosen[i]+1
digits[idx]+=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(set) do
res = comb(res,set,n,i,append(deep_copy(chosen),set[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
printf(1,"%V\n",{comb({0,0},nums,i)})
end for