Concatenative topics
Concatenative meta
Other languages
Meta
The Fibonacci numbers are the numbers in the following integer sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144
int fib(int n) { if (n <= 1) return n; return fib(n - 1) + fib(n - 2); } int main() { int n = 9; printf("%dth Fibonacci Number: %d", n, fib(n)); return 0; }
@on-reset ( -> ) #0009 fib #010e DEO BRK @fib ( num* -- numfib* ) #0001 GTH2k ?{ POP2 JMP2r } SUB2k fib STH2 INC2 SUB2 fib STH2r ADD2 JMP2r
using std.manip using std.cond using std.out fib == [: [1 - : 1 - fib ⟷ fib +] [] ⍉ 1 > ?] 9 fib .nl
include "cores/select.cal" include "std/io.cal" func fib begin let cell n n ! if n @ 1 <= then n @ return else n @ 1 - fib n @ 2 - fib + return end end 9 fib printdec new_line
uses io fun Fib n[Uint] => n 1 <= if n else n 1 - Fib n 2 - Fib + 9 Fib IO.PrintLn
This revision created on Fri, 12 Jul 2024 20:52:15 by lordoftrident (Add Concata)