Generator/Exponential: Difference between revisions

m
Line 2,647:
<syntaxhighlight lang="m2000 interpreter">
Module Generator {
PowGen = Lambda (e)-> {
=lambda i=0, e -> {
i++ = Lambda
=i**e=0, // closure
e // closure
=PowGen() -> {
i++
=z i**e
=PowGen() }
z=Squares()}
Squares=Lambda
Squares=lambda PowGen=PowGen(2) ->{ // closure
\\ a new line to doc$ ->{
if z=m then z =Squares PowGen()
}
Cubes=Lambda PowGen=PowGen(3) -> {
PowGen=PowGen(3) // closure
while m<Z-> {m=cubes()}
= PowGen()
}
Filter=Lambda
Filter=Lambda z=Squares(), Squares, m,// Cubes->{closure
Squares, // closure
m, // closure
Cubes // closure
->{
while m<z :m=cubes():end while
if z=m then z=Squares()
= z : z=Squares()
}
}
Squares=lambda PowGen=PowGen(2) ->{
=PowGen()
}
Cubes=Lambda PowGen=PowGen(3) -> {
=PowGen()
}
Filter=Lambda z=Squares(), Squares, m, Cubes->{
while m<Z {m=cubes()}
if z=m then z=Squares()
=z
z=Squares()
}
For i=1 to 20 : dropit=Filter() :Next i
Document doc$="Non-cubic squares (21st to 30th)"
Print doc$
\\ a new line to doc$
doc$={
} \\ a new line to doc$
}
For i=1 to 10 {
f=Filter()
Print Format$("I: {0::-2}, F: {1}",i+20, f)
doc$=Format$("I: {0::-2}, F: {1}",i+20, f)+{
}
}Next
Clipboard doc$
}
404

edits