RosettaCodeData/Task/Combinations/M2000-Interpreter/combinations-1.m2000

42 lines
1.3 KiB
Plaintext

Module Checkit {
Global a$
Document a$
Module Combinations (m as long, n as long){
Module Level (n, s, h) {
If n=1 then {
while Len(s) {
Print h, car(s)
ToClipBoard()
s=cdr(s)
}
} Else {
While len(s) {
call Level n-1, cdr(s), cons(h, car(s))
s=cdr(s)
}
}
Sub ToClipBoard()
local m=each(h)
Local b$=""
While m {
b$+=If$(Len(b$)<>0->" ","")+Format$("{0::-10}",Array(m))
}
b$+=If$(Len(b$)<>0->" ","")+Format$("{0::-10}",Array(s,0))+{
}
a$<=b$ ' assign to global need <=
End Sub
}
If m<1 or n<1 then Error
s=(,)
for i=0 to n-1 {
s=cons(s, (i,))
}
Head=(,)
Call Level m, s, Head
}
Clear a$
Combinations 3, 5
ClipBoard a$
}
Checkit