-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Manobal-Singh-Bagady/patterns
Add code for Pattern 10, Pattern 6, Pattern 7, Pattern 8, and Pattern 9
- Loading branch information
Showing
5 changed files
with
571 additions
and
0 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
CODE/Step1-Learn the basics/Lec2-Build Up Logical thinking/Pattern10.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Pattern 10\n", | ||
"\n", | ||
"- pattern:\n", | ||
"\n", | ||
" ```text\n", | ||
" n=3 \n", | ||
" *\n", | ||
" **\n", | ||
" ***\n", | ||
" **\n", | ||
" *\n", | ||
" ```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"*\n", | ||
"**\n", | ||
"***\n", | ||
"****\n", | ||
"*****\n", | ||
"****\n", | ||
"***\n", | ||
"**\n", | ||
"*\n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Pattern 10\n", | ||
"def nStarTriangle(n: int) -> None:\n", | ||
" for i in range(1, n + 1):\n", | ||
" print(\"*\" * i)\n", | ||
" for i in range(n - 1, -1, -1):\n", | ||
" print(\"*\" * i)\n", | ||
"\n", | ||
"\n", | ||
"nStarTriangle(5)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"- Python Specific Solution" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"*\n", | ||
"**\n", | ||
"***\n", | ||
"****\n", | ||
"*****\n", | ||
"****\n", | ||
"***\n", | ||
"**\n", | ||
"*\n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Pattern 10\n", | ||
"def nStarTriangle(n: int) -> None:\n", | ||
" print(\n", | ||
" *([\"*\" * i for i in range(1, n + 1)] + [\"*\" * i for i in range(n - 1, -1, -1)]),\n", | ||
" sep=\"\\n\"\n", | ||
" )\n", | ||
"\n", | ||
"\n", | ||
"nStarTriangle(5)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
107 changes: 107 additions & 0 deletions
107
CODE/Step1-Learn the basics/Lec2-Build Up Logical thinking/Pattern6.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Pattern 6\n", | ||
"\n", | ||
"- pattern\n", | ||
"\n", | ||
" ```text\n", | ||
" n=5\n", | ||
" 1 2 3 4 5\n", | ||
" 1 2 3 4\n", | ||
" 1 2 3 \n", | ||
" 1 2 \n", | ||
" 1 \n", | ||
" ```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"1 2 3 4 5 \n", | ||
"1 2 3 4 \n", | ||
"1 2 3 \n", | ||
"1 2 \n", | ||
"1 \n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Pattern 6\n", | ||
"class Solution:\n", | ||
" def printTriangle(self, N):\n", | ||
" for i in range(N, 0, -1):\n", | ||
" for j in range(1, i + 1):\n", | ||
" print(j, end=\" \")\n", | ||
" print()\n", | ||
"\n", | ||
"\n", | ||
"Solution().printTriangle(5)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"- python specific" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"1 2 3 4 5\n", | ||
"1 2 3 4\n", | ||
"1 2 3\n", | ||
"1 2\n", | ||
"1\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Pattern 6\n", | ||
"class Solution:\n", | ||
" def printTriangle(self, N):\n", | ||
" print(*[\" \".join(map(str, range(1, i + 1))) for i in range(N, 0, -1)], sep=\"\\n\")\n", | ||
"\n", | ||
"\n", | ||
"Solution().printTriangle(5)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
108 changes: 108 additions & 0 deletions
108
CODE/Step1-Learn the basics/Lec2-Build Up Logical thinking/Pattern7.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Pattern 7\n", | ||
"\n", | ||
"- pattern:\n", | ||
" ```text\n", | ||
" n=5\n", | ||
" *\n", | ||
" *** \n", | ||
" *****\n", | ||
" *******\n", | ||
" *********\n", | ||
" ```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
" *\n", | ||
" ***\n", | ||
" *****\n", | ||
" *******\n", | ||
"*********\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Pattern 7\n", | ||
"class Solution:\n", | ||
" def printTriangle(self, N):\n", | ||
" for i in range(N):\n", | ||
" for _ in range(N - i - 1):\n", | ||
" print(\" \", end=\"\")\n", | ||
" for _ in range(2 * i + 1):\n", | ||
" print(\"*\", end=\"\")\n", | ||
" print()\n", | ||
"\n", | ||
"\n", | ||
"Solution().printTriangle(5)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"- python specific answer" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
" *\n", | ||
" ***\n", | ||
" *****\n", | ||
" *******\n", | ||
"*********\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Pattern 7\n", | ||
"class Solution:\n", | ||
" def printTriangle(self, N):\n", | ||
" print(*[\" \" * (N - i - 1) + \"*\" * (2 * i + 1) for i in range(N)], sep=\"\\n\")\n", | ||
"\n", | ||
"\n", | ||
"Solution().printTriangle(5)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.