Skip to content

Commit

Permalink
Merge pull request #2 from Manobal-Singh-Bagady/patterns
Browse files Browse the repository at this point in the history
Add code for Pattern 10, Pattern 6, Pattern 7, Pattern 8, and Pattern 9
  • Loading branch information
Manobal-Singh-Bagady authored Oct 31, 2024
2 parents d40e75c + 1a6ffbd commit 33468ff
Show file tree
Hide file tree
Showing 5 changed files with 571 additions and 0 deletions.
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
}
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
}
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
}
Loading

0 comments on commit 33468ff

Please sign in to comment.