September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
29
Task/Ordered-Partitions/Phix/ordered-partitions.phix
Normal file
29
Task/Ordered-Partitions/Phix/ordered-partitions.phix
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
function partitions(sequence s)
|
||||
integer N = sum(s)
|
||||
sequence set = tagset(N), perm,
|
||||
results = {}, result, resi
|
||||
for i=1 to factorial(N) do
|
||||
perm = permute(i,set)
|
||||
integer n = 1
|
||||
result = {}
|
||||
for j=1 to length(s) do
|
||||
resi = {}
|
||||
for k=1 to s[j] do
|
||||
resi = append(resi,perm[n])
|
||||
n += 1
|
||||
end for
|
||||
result = append(result,sort(resi))
|
||||
end for
|
||||
if not find(result,results) then
|
||||
results = append(results,result)
|
||||
end if
|
||||
end for
|
||||
return sort(results)
|
||||
end function
|
||||
|
||||
ppOpt({pp_Nest,1})
|
||||
pp(partitions({2,0,2}))
|
||||
pp(partitions({1,1,1}))
|
||||
pp(partitions({1,2,0,1}))
|
||||
pp(partitions({}))
|
||||
pp(partitions({0,0,0}))
|
||||
Loading…
Add table
Add a link
Reference in a new issue