Difference between revisions of "Manuals/calci/Pascal Triangle Fun"

From ZCubes Wiki
Jump to navigation Jump to search
(Created page with " ==Pascal Triangle Fun== === Sierpiński triangle == <pre> //with 32 m=32; pt=PASCALTRIANGLE(m).$(x=>x%2) a=pt .map( function (r,i) { var prefix= (REPEATCHAR(" ",(2...")
 
 
(10 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
==Pascal Triangle Fun==
 
==Pascal Triangle Fun==
  
=== Sierpiński triangle ==  
+
=== Sierpiński triangle ===
 +
 
 +
[https://en.wikipedia.org/wiki/Sierpi%C5%84ski_triangle Sierpierski Triangle]
 +
 
 
<pre>
 
<pre>
 
//with 32
 
//with 32
Line 23: Line 26:
  
 
</pre>
 
</pre>
 +
 +
===Fibonacci and Pascal Triangle===
 +
<pre>
 +
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)
 +
}
 +
)
 +
</pre>
 +
 +
 +
==Pascal Triangle and Figurate Numbers==
 +
 +
PASCALTRIANGLE(10)
 +
 +
[https://en.wikipedia.org/wiki/Figurate_number]
 +
 +
[https://www.mathsisfun.com/algebra/triangular-numbers.html Triangular Numbers]
 +
 +
[https://en.wikipedia.org/wiki/Tetrahedral_number Tetrahedral Numbers]
 +
 +
[https://en.wikipedia.org/wiki/Figurate_number Figurate Number]
 +
 +
<pre>
 +
figuratenumbers=(n,r)=>(n+r-1)!C!r;
 +
a=[1..10,0..10]@figuratenumbers;
 +
a.parts(10)
 +
</pre>
 +
 +
==Lucas, Fibonacci, Golden Ratio Relationship ==
 +
 +
<pre>
 +
FIBONACCI(50)
 +
 +
LUCAS(50)
 +
 +
FIBONACCI(50)
 +
.pieces(2)
 +
.map(r=>r[1]/r[0])
 +
 +
GOLDENRATIO()
 +
 +
LUCAS(50)
 +
.pieces(2)
 +
.map(r=>r[1]/r[0])
 +
 +
ROUND((GOLDENRATIO())^(1..10))
 +
 +
[(1+√5)/2,(1+√5)/2]
 +
 +
ops.on;
 +
[(1+√5d100)/2,(1-√5d100)/2]
 +
 +
</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>
 +
 +
Now we can use:
 +
<pre>
 +
PASCALTRIANGLE(10,true)
 +
<pre>

Latest revision as of 12:33, 7 August 2020


Pascal Triangle Fun

Sierpiński triangle

Sierpierski 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)
	}
)


Pascal Triangle and Figurate Numbers

PASCALTRIANGLE(10)

[1]

Triangular Numbers

Tetrahedral Numbers

Figurate Number

figuratenumbers=(n,r)=>(n+r-1)!C!r;
a=[1..10,0..10]@figuratenumbers;
a.parts(10)

Lucas, Fibonacci, Golden Ratio Relationship

FIBONACCI(50)

LUCAS(50)

FIBONACCI(50)
	.pieces(2)
	.map(r=>r[1]/r[0])
	
GOLDENRATIO()	
	
LUCAS(50)
	.pieces(2)
	.map(r=>r[1]/r[0])

ROUND((GOLDENRATIO())^(1..10))

[(1+√5)/2,(1+√5)/2]

ops.on;
[(1+√5d100)/2,(1-√5d100)/2]


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)
			)
		}
	);


Now we can use:
PASCALTRIANGLE(10,true)