Skip to content

Commit

Permalink
Add day 15
Browse files Browse the repository at this point in the history
  • Loading branch information
MadhavBahl committed Jan 9, 2019
1 parent ba0252e commit a0a245c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions day15/README.md
@@ -0,0 +1,56 @@
![cover](./cover.png)

# Day 15 - Recursion Series Part C

Today's Problem - Pascal's Triangle

**Question** -- Write a function that takes an integer n as iniput and prints first n lines of Pascal's Triangle

**Example**

```
input: 5
output:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
```

![ques](./ques.png)

## JavaScript Implementation

### [Solution](./JavaScript/pascal_MadhavBahlMD)

```js
/**
* @author MadhavBahlMD
* @date 09/01/2018
*/

function findPascal (row, col) {
if (col === 1 || col === row) {
return 1;
} else {
return findPascal (row-1, col-1) + findPascal (row-1, col);
}
}

function printPascal (num) {
let currentRow;
for (let i=1; i<=num; i++) {
currentRow = '';
for (let j=1; j<=i; j++) {
currentRow += findPascal (i, j) + ' ';
}
console.log(currentRow);
}
}

console.log ('/* ===== Pascal\'s Triangle for n = 5\n');
printPascal (5);
console.log ('\n/* ===== Pascal\'s Triangle for n = 7\n');
printPascal (7);
```
Binary file added day15/cover.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added day15/ques.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a0a245c

Please sign in to comment.