From c32a8126a6b01bfb48d24210d97b5806ac117080 Mon Sep 17 00:00:00 2001 From: linsy king Date: Tue, 4 Apr 2023 18:42:11 +0800 Subject: [PATCH] update fib function --- examples/syn.cat | 1 + examples/syn.meow | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/examples/syn.cat b/examples/syn.cat index e3f2881..dcbf99a 100644 --- a/examples/syn.cat +++ b/examples/syn.cat @@ -25,3 +25,4 @@ num x = ! if eq len x "S0" spack digit x cat cat cat cat cat cat cat `add mul "` spack x = cat cat `"` x `"` leq x y = in x y show x = ! if leq len x digit "9" spack revdigit x cat cat cat cat `cat show "` let "SSSSSSSSSS" "S" sub x let "SSSSSSSSSS" "" x `" revdigit "` let "SSSSSSSSSS" "" x `"` +fib x = if eq x zero zero ! if leq x num "2" spack num "1" "add fib pred x fib pred pred x" diff --git a/examples/syn.meow b/examples/syn.meow index 7462b58..8dd2b44 100644 --- a/examples/syn.meow +++ b/examples/syn.meow @@ -193,3 +193,15 @@ show(x) { }; !(if(leq(len(x), digit("9")), spack(revdigit(x)) , `cat show "` + rem + `" revdigit "` + la + `"`)) } + +fib(x) { + if( + eq(x, zero()), + zero(), + !(if( + leq(x, num("2")), + spack(num("1")), + `add fib pred x fib pred pred x` + )) + ) +}