From f268a4df7b779ad4994f3e155bb8da19383494bb Mon Sep 17 00:00:00 2001 From: ricmaps Date: Wed, 24 Jun 2026 16:24:52 -0300 Subject: [PATCH] Add Fibonacci in Forth --- archive/f/forth/fibonacci.fth | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 archive/f/forth/fibonacci.fth diff --git a/archive/f/forth/fibonacci.fth b/archive/f/forth/fibonacci.fth new file mode 100644 index 000000000..f6577e872 --- /dev/null +++ b/archive/f/forth/fibonacci.fth @@ -0,0 +1,17 @@ +: fibonacci ( n -- ) + 0 1 rot 0 ?do \ prepare the stack and loop + tuck + \ calculate the next fibonacci number + i 1+ 0 .r ." : " \ print the current index + over 0 .r cr \ print the current fibonacci number + loop + 2drop ; + +: usage ( -- ) ." Usage: please input the count of fibonacci numbers to output" cr ; + +: main + argc @ 2 < if usage exit then + 1 arg s>number? 0= if usage exit else drop then + fibonacci ; + +main +bye