User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
algorithm:factorial_recursive [2012/10/04 21:59]
127.0.0.1 external edit
algorithm:factorial_recursive [2015/02/02 08:28] (current)
Line 1: Line 1:
-====== Algorithm ======+======= λ Factorial - recursive ====== 
 + 
 +<​nowiki>​ 
 +======= Algorithm ​=======
 <syntax js> <syntax js>
 function fac(x) { function fac(x) {
Line 9: Line 12:
 </​syntax>​ </​syntax>​
  
-====== Support ======+======= Support ​=======
 <syntax js> <syntax js>
 function run() { function run() {
Line 16: Line 19:
 </​syntax>​ </​syntax>​
  
-====== Visualisation ======+======= Tests ======= 
 +<syntax js> 
 +function testTen() { 
 +    assert (fac(10) === 3628800, "​fac(10)"​);​ 
 +
 + 
 +function testSeven() { 
 +    assert (fac(7) === 5040 , "​fac(7)"​);​ 
 +}</​syntax>​ 
 + 
 +======= Options ======= 
 +<syntax js> 
 +
 +    "​title":"​Factorial - recursive",​ 
 +    "​height":"​150px"​ 
 +
 +</​syntax>​ 
 + 
 +======= Visualisation ​=======
 <syntax html> <syntax html>
 <​html>​ <​html>​
Line 29: Line 50:
             var stack = x.stack;             var stack = x.stack;
             for (var i=stack.length-1;​ i>=0; i--) {             for (var i=stack.length-1;​ i>=0; i--) {
-                var x2 = stack[i].executionContext;​ +                var = stack[i].lookupInScope("​x"​);​
-                var a = x2.lookupInScope("​x"​);​+
                 if (a) {                 if (a) {
                     html = a+" * "​+html;​                     html = a+" * "​+html;​
Line 46: Line 66:
             else {             else {
                 var a = x.lookupInScope("​x"​);​                 var a = x.lookupInScope("​x"​);​
 +                if (!a) a = 50;
                 html = html + "​fac("​+a+"​)";​                 html = html + "​fac("​+a+"​)";​
             }             }
Line 53: Line 74:
     </​script>​     </​script>​
   </​head>​   </​head>​
-  <body id="​container">​+  <body id="​container" style="​height:​150px">
   </​body>​   </​body>​
 </​html>​ </​html>​
 </​syntax>​ </​syntax>​
 +</​nowiki>​
algorithm/factorial_recursive.1349413170.txt.gz · Last modified: 2015/02/02 08:23 (external edit)