about summary refs log tree commit diff
path: root/examples/fac.ccl
blob: 2d53d791afa1933b2a19a99a278abe0334f0c228 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
^=z / z = 0
F/actorial / n -- nth-factorial
{
    z?+#; / n == 0 ? return 1

    =a$a$a / dup n
    - @F=a / a = F(n - 1)

    =b / b = n

    / push a * b
    b[$a]
    $b-=b
    b[*]
}

I/terative factorial / n -- nth-fctorial
{
    z?+#;   / n == 0 ? return 1

    =c$c    / c = n - 1
    $c-=c   / --c

    c (                     / while c > 0
        $c                  /   push c
        =a=ba[$b]$a-=aa[*]  /   multiply 2 toppest nums
        $c-=c               /   --c
    )
}

^++++++
^++++++ @F
^++++++ @I