Skip to content

Commit db4223b

Browse files
committed
Added math/pascals_triangle.py
1 parent 0422b17 commit db4223b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

pygorithm/math/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
from . import factorial
66
from . import lcm
77
from . import lcm_using_gcd
8+
from . import pascals_triangle
89
from . import sieve_of_eratosthenes
910

1011
__all__ = [
1112
'conversion',
1213
'factorial',
1314
'lcm_using_gcd',
1415
'lcm',
16+
'pascals_triangle',
1517
'sieve_of_eratosthenes'
1618
]
17-

pygorithm/math/pascals_triangle.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'''
2+
Author: OMKAR PATHAK
3+
Created at: 26th August 2017
4+
'''
5+
6+
def pascals_triangle(n):
7+
'''
8+
:param n: total number of lines in pascal triangle
9+
10+
Pascal’s triangle is a triangular array of the binomial coefficients.
11+
Following are the first 6 rows of Pascal’s Triangle (when n = 6)
12+
1
13+
1 1
14+
1 2 1
15+
1 3 3 1
16+
1 4 6 4 1
17+
1 5 10 10 5 1
18+
'''
19+
20+
for line in range(1, n + 1):
21+
C = 1
22+
for i in range(1, line + 1):
23+
print(C, end = ' ')
24+
C = C * (line - i) // i
25+
print()

0 commit comments

Comments
 (0)