|
|
last edited 10 years ago by Bill Page |
1 2 3 4 5 6 | ||
Editor: Bill Page
Time: 2014/09/19 06:12:45 GMT+0 |
||
Note: |
changed: - while j(n)<=#a repeat - --output j - j(n):=j(n)+1 - k:=n - while j(n)>#a and k>1 repeat - k:=k-1 - j(k):=j(k)+1 - for i in k..n-1 repeat j(i+1):=j(i)+1 - if j(n)<=#a then r:=concat(r,[a(j(i)) for i in 1..n]) k:=n while k>0 and j(k)+n-k<#a repeat j(k):=j(k)+1 for i in k..n-1 repeat j(i+1):=j(i)+1 r:=concat(r,[a(j(i)) for i in 1..n]) k:=n; while j(k)+n-k>=#a and k>1 repeat k:=k-1 added: choose([1],1) choose([1,2],1) choose([1,2],2)
choose(a,n) == j:=[i for i in 1..n] r:=[[a(j(i)) for i in 1..n]] k:=n while k>0 and j(k)+n-k<#a repeat j(k):=j(k)+1 for i in k..n-1 repeat j(i+1):=j(i)+1 r:=concat(r, [a(j(i)) for i in 1..n]) k:=n; while j(k)+n-k>=#a and k>1 repeat k:=k-1 if binomial(#a, n)~=#r then error "error in choose" return r
choose([1],1)
Compiling function choose with type (List(PositiveInteger),PositiveInteger) -> List(List(PositiveInteger))
(1) |
choose([1,2], 1)
(2) |
choose([1,2], 2)
(3) |
choose([1,2, 3], 1)
(4) |
choose([1,2, 3], 2)
(5) |
choose([1,2, 3], 3)
(6) |
choose([x,y, z, w], 1)
Compiling function choose with type (List(OrderedVariableList([x,y, z , w])), PositiveInteger) -> List(List(OrderedVariableList([x, y, z, w] )))
(7) |
choose([x,y, z, w], 2)
(8) |
choose([x,y, z, w], 3)
(9) |
choose([x,y, z, w], 4)
(10) |