Skip to content

Instantly share code, notes, and snippets.

@t0mdicks0n
Created April 7, 2017 06:02
Show Gist options
  • Select an option

  • Save t0mdicks0n/bd924210a031a2470e3618d871dc3b4b to your computer and use it in GitHub Desktop.

Select an option

Save t0mdicks0n/bd924210a031a2470e3618d871dc3b4b to your computer and use it in GitHub Desktop.
awdawd
var pascal = [
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
];
function generetaPascal(numRows) {
var triangle;
function pyramid(targetSum) {
if (triangle.length === numRows) {
return triangle;
}
// get new sum by checking the length of the last sum in the triangle and multiply it by two
// wanted length = triangle.length - 2
// rest = wantedSum - 2
//
if (numRows.length === 0) {
triangle.push([1]);
} else if (numRows.length === 1) {
triangle.push([1]);
} else {
var newSum = pascal.length * 2;
var wantedLen = triangle.length - 2;
var specialChar = pascal.length;
var rest = newSum - 2 - (specialChar * 2);
if (newSum === specialChar + 2) {
triangle.push(1, specialChar, 1);
return;
} else {
}
triangle.push([1, specialChar, Number([].join()), specialChar, 1]);
}
restNumArr = [];
}
pyramid(triangle.length * 2);
pyramid(1);
return triangle;
}
1, pascal.length
2, pascal.length * 2
4, pascal.length * 2
8, pascal.length * 2
16, pascal.length * 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment