Skip to content

Commit 247dbbf

Browse files
committed
lists-Khayyam-Pascal triangle
1 parent 6750c01 commit 247dbbf

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

Lists-binomial coefficients.ipynb

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "c74ffdc5",
6+
"metadata": {},
7+
"source": [
8+
"# Python: Everything\n",
9+
"- Lists\n",
10+
" - Example: Khayyam-Pascal's triangle\n",
11+
"<br>\n",
12+
"<br>$\\binom{n}{k}=\\binom{n-1}{k}+\\binom{n-1}{k-1}$\n",
13+
"<br>\n",
14+
"- <br> https://github.com/ostad-ai/Python-Everything"
15+
]
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"id": "35a33f56",
20+
"metadata": {},
21+
"source": [
22+
"First, we define a two-dimensional list with all ones.\n",
23+
"<br>Then, we use the above rule:"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 4,
29+
"id": "4ea9ccc0",
30+
"metadata": {},
31+
"outputs": [
32+
{
33+
"name": "stdout",
34+
"output_type": "stream",
35+
"text": [
36+
"1\n",
37+
"1 1\n",
38+
"1 2 1\n",
39+
"1 3 3 1\n",
40+
"1 4 6 4 1\n",
41+
"1 5 10 10 5 1\n",
42+
"1 6 15 20 15 6 1\n",
43+
"1 7 21 35 35 21 7 1\n",
44+
"1 8 28 56 70 56 28 8 1\n",
45+
"1 9 36 84 126 126 84 36 9 1\n"
46+
]
47+
}
48+
],
49+
"source": [
50+
"N=10 #no. of rows of the triangle\n",
51+
"binomials=[[1 for k in range(n+1)] for n in range(N)]\n",
52+
"for n in range(2,N):\n",
53+
" for k in range(1,n):\n",
54+
" binomials[n][k]=binomials[n-1][k]+binomials[n-1][k-1]\n",
55+
"for n in range(N):\n",
56+
" print(*binomials[n])"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"id": "9c7ef14f",
63+
"metadata": {},
64+
"outputs": [],
65+
"source": []
66+
}
67+
],
68+
"metadata": {
69+
"kernelspec": {
70+
"display_name": "Python 3 (ipykernel)",
71+
"language": "python",
72+
"name": "python3"
73+
},
74+
"language_info": {
75+
"codemirror_mode": {
76+
"name": "ipython",
77+
"version": 3
78+
},
79+
"file_extension": ".py",
80+
"mimetype": "text/x-python",
81+
"name": "python",
82+
"nbconvert_exporter": "python",
83+
"pygments_lexer": "ipython3",
84+
"version": "3.8.10"
85+
}
86+
},
87+
"nbformat": 4,
88+
"nbformat_minor": 5
89+
}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# Python-Everything
2-
1) Lists: Introduction
2+
3+
1) Lists: Introduction
4+
2) Lists: Example, computing Khayyam-Pascal's triangle

0 commit comments

Comments
 (0)