From 445784a629c99336d47b31ea9540bd95bbb97dc1 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 31 Mar 2025 17:22:19 +0300 Subject: Add 2 more examples - Number parser - Factorial (2 ways to implement) --- examples/fac.ccl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/fac.ccl (limited to 'examples/fac.ccl') diff --git a/examples/fac.ccl b/examples/fac.ccl new file mode 100644 index 0000000..2d53d79 --- /dev/null +++ b/examples/fac.ccl @@ -0,0 +1,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 -- cgit 1.4.1