19 lines
376 B
Text
19 lines
376 B
Text
beads 1 program Factorial
|
|
// only works for cardinal numbers 0..N
|
|
calc main_init
|
|
log to_str(Iterative(4)) // 24
|
|
log to_str(Recursive(5)) // 120
|
|
|
|
calc Iterative(
|
|
n:num -- number of iterations
|
|
):num -- result
|
|
var total = 1
|
|
loop from:2 to:n index:ix
|
|
total = ix * total
|
|
return total
|
|
|
|
calc Recursive ditto
|
|
if n <= 1
|
|
return 1
|
|
else
|
|
return n * Recursive(n-1)
|