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

33 lines
943 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
Module Checkit {
2025-02-27 18:35:13 -05:00
Function Combinations (m as long, n as long){
Global a$
Document a$
2023-07-01 11:58:00 -04:00
Module Level (n, s, h) {
2025-02-27 18:35:13 -05:00
If n=1 then
while Len(s)
a$<=h#str$("-")+"-"+car(s)#str$()+{
}
2023-07-01 11:58:00 -04:00
s=cdr(s)
2025-02-27 18:35:13 -05:00
End While
Else
While len(s)
2023-07-01 11:58:00 -04:00
call Level n-1, cdr(s), cons(h, car(s))
s=cdr(s)
2025-02-27 18:35:13 -05:00
End While
End if
2023-07-01 11:58:00 -04:00
}
If m<1 or n<1 then Error
s=(,)
2025-02-27 18:35:13 -05:00
for i=0 to n-1
Append s, (i,)
next
s=s#sort()
2023-07-01 11:58:00 -04:00
Head=(,)
Call Level m, s, Head
2025-02-27 18:35:13 -05:00
=a$
2023-07-01 11:58:00 -04:00
}
2025-02-27 18:35:13 -05:00
ClipBoard Combinations( 3, 5)
report clipboard$
2023-07-01 11:58:00 -04:00
}
Checkit