Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Combinations/Maxima/combinations.maxima
Normal file
26
Task/Combinations/Maxima/combinations.maxima
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
next_comb(n, p, a) := block(
|
||||
[a: copylist(a), i: p],
|
||||
if a[1] + p = n + 1 then return(und),
|
||||
while a[i] - i >= n - p do i: i - 1,
|
||||
a[i]: a[i] + 1,
|
||||
for j from i + 1 thru p do a[j]: a[j - 1] + 1,
|
||||
a
|
||||
)$
|
||||
|
||||
combinations(n, p) := block(
|
||||
[a: makelist(i, i, 1, p), v: [ ]],
|
||||
while a # 'und do (v: endcons(a, v), a: next_comb(n, p, a)),
|
||||
v
|
||||
)$
|
||||
|
||||
combinations(5, 3);
|
||||
/* [[1, 2, 3],
|
||||
[1, 2, 4],
|
||||
[1, 2, 5],
|
||||
[1, 3, 4],
|
||||
[1, 3, 5],
|
||||
[1, 4, 5],
|
||||
[2, 3, 4],
|
||||
[2, 3, 5],
|
||||
[2, 4, 5],
|
||||
[3, 4, 5]] */
|
||||
Loading…
Add table
Add a link
Reference in a new issue