λ Fibonacci - recursive

======= Algorithm ======= <syntax js> function fib(n) { if (n < 2) { return n; } return fib(n-1) + fib(n-2); } </syntax> ======= Support ======= <syntax js> function run(args) { result = null; result = fib(args.n); } </syntax> ======= Tests ======= <syntax js> function testTen() { assert (fib(10) === 55, "fib(10)"); } function testEighteen() { assert (fib(18) === 2584 , "fib(18)"); }</syntax> ======= Options ======= <syntax js> { "title":"Fibonacci - recursive", "height":"150px" } </syntax> ======= Visualisation ======= <syntax html> <html> <head> <style type="text/css"> input {width:50px;} </style> <script type="text/javascript"> function update(n, x) { var element = document.getElementById("result"); var result = x.lookupInScope("result"); var n = x.lookupInScope("n"); if (result) { element.innerHTML = "= "+result; } else if (n) { element.innerHTML = "Calculating fib("+n+")"; } else { element.innerHTML = ""; } } function args() { var n = document.getElementById('n').value; return {n:n}; } </script> </head> <body> fib( <input id="n" value=12> ) <div id="result"></div> </body> </html> </syntax>