Difference between revisions of "Manuals/calci/Pascal Triangle Fun"
Jump to navigation
Jump to search
Line 43: | Line 43: | ||
) | ) | ||
</pre> | </pre> | ||
+ | |||
+ | ===Pretty Pascal Triangle=== | ||
+ | <pre> | ||
+ | m=10; | ||
+ | pt=PASCALTRIANGLE(m) | ||
+ | pt | ||
+ | .map( | ||
+ | function (r,i) | ||
+ | { | ||
+ | var prefix= (REPEATCHAR(" ",(2*m-(2*i+1))/2).split("")); | ||
+ | return( | ||
+ | prefix | ||
+ | .concat(r.join(", ,").split(",")) | ||
+ | .concat(prefix) | ||
+ | ) | ||
+ | } | ||
+ | ); | ||
+ | |||
+ | <pre> |
Revision as of 18:12, 6 August 2020
Pascal Triangle Fun
Sierpiński triangle
//with 32 m=32; pt=PASCALTRIANGLE(m).$(x=>x%2) a=pt .map( function (r,i) { var prefix= (REPEATCHAR(" ",(2*m-(2*i+1))/2).split("")); return( prefix .concat(r.join(", ,").split(",")) .concat(prefix) ) } ); (a);
Fibonacci and Pascal Triangle
FIBONNACI(100) b=PASCALTRIANGLE(100) b.map( function calcfib(r,i,d) { var fib=0; var j=0; for(var xi=i;xi>=0;xi--) { fib+=isNaN(d[xi][j])?0:d[xi][j]; j++; } return(fib) } )
Pretty Pascal Triangle
m=10; pt=PASCALTRIANGLE(m) pt .map( function (r,i) { var prefix= (REPEATCHAR(" ",(2*m-(2*i+1))/2).split("")); return( prefix .concat(r.join(", ,").split(",")) .concat(prefix) ) } );