46 lines
1.2 KiB
Plaintext
46 lines
1.2 KiB
Plaintext
Module StepByStep {
|
|
Function CombinationsStep (a, nn) {
|
|
c1=lambda (&f, &a) ->{
|
|
=car(a) : a=cdr(a) : f=len(a)=0
|
|
}
|
|
m=len(a)
|
|
c=c1
|
|
n=m-nn+1
|
|
p=2
|
|
while m>n {
|
|
c1=lambda c2=c,n=p, z=(,) (&f, &m) ->{
|
|
if len(z)=0 then z=cdr(m)
|
|
=cons(car(m),c2(&f, &z))
|
|
if f then z=(,) : m=cdr(m) : f=len(m)+len(z)<n
|
|
}
|
|
c=c1
|
|
p++
|
|
m--
|
|
}
|
|
=lambda c, a (&f) -> {
|
|
=c(&f, &a)
|
|
}
|
|
}
|
|
k=false
|
|
StepA=CombinationsStep((1, 2, 3, 4,5), 3)
|
|
while not k {
|
|
Print StepA(&k)
|
|
}
|
|
k=false
|
|
StepA=CombinationsStep((0, 1, 2, 3, 4), 3)
|
|
while not k {
|
|
Print StepA(&k)
|
|
}
|
|
k=false
|
|
StepA=CombinationsStep(("A", "B", "C", "D","E"), 3)
|
|
while not k {
|
|
Print StepA(&k)
|
|
}
|
|
k=false
|
|
StepA=CombinationsStep(("CAT", "DOG", "BAT"), 2)
|
|
while not k {
|
|
Print StepA(&k)
|
|
}
|
|
}
|
|
StepByStep
|