summaryrefslogtreecommitdiff
path: root/vendor/bundle/ruby/3.4.0/gems/rouge-4.5.2/lib/rouge/demos/mathematica
blob: b650247f428d324b7d3f40226f9661a725d7e99e (plain)
1
2
3
4
5
6
7
8
(* Fibonacci numbers with memoization *)

fib::usage = "f[n] calculates the n'th Fibonacci number.";
fib[0] = fib[1] = 1;
fib[n_Integer?Positive]:= fib[n] = fib[n-1] + fib[n-2];

In[4]:= fib[42]
Out[4]= 433494437