Skip to content

Commit

Permalink
Merge pull request #3 from Manobal-Singh-Bagady/patterns
Browse files Browse the repository at this point in the history
Add code for Pattern 11, Pattern 12, Pattern 13, and Pattern 14
  • Loading branch information
Manobal-Singh-Bagady authored Oct 31, 2024
2 parents 33468ff + eecdb0b commit 5715531
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pattern 11\n",
"\n",
"- pattern:\n",
"\n",
" ```text \n",
" n=3\n",
" 1\n",
" 0 1\n",
" 1 0 1\n",
" ```"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 \n",
"0 1 \n",
"1 0 1 \n",
"0 1 0 1 \n",
"1 0 1 0 1 \n"
]
}
],
"source": [
"# Pattern 11\n",
"def nBinaryTriangle(n: int) -> None:\n",
" for i in range(n):\n",
" str = 1 if i%2==0 else 0\n",
" for j in range(i+1):\n",
" print(str, end=' ')\n",
" str^=1\n",
" print()\n",
"\n",
"\n",
"nBinaryTriangle(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,74 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pattern 12\n",
"\n",
"- pattern:\n",
"\n",
" ```text\n",
" 1 1\n",
" 1 2 2 1\n",
" 1 2 3 3 2 1\n",
" ```"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 1 \n",
"1 2 2 1 \n",
"1 2 3 3 2 1 \n",
"1 2 3 4 4 3 2 1 \n",
"1 2 3 4 5 5 4 3 2 1 \n"
]
}
],
"source": [
"# Pattern 12\n",
"def numberCrown(n: int) -> None:\n",
" spaces = 4*(n-1)\n",
" for i in range(1,n+1):\n",
" for j in range(1,i+1):\n",
" print(j, end=' ')\n",
" print(' '*spaces, end='')\n",
" spaces -= 4\n",
" for j in range(i,0,-1):\n",
" print(j, end=' ')\n",
" print()\n",
"\n",
"\n",
"numberCrown(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,72 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pattern 13\n",
"\n",
"- pattern:\n",
"\n",
" ```text \n",
" n=3\n",
" 1\n",
" 2 3\n",
" 4 5 6\n",
" ```"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 \n",
"2 3 \n",
"4 5 6 \n",
"7 8 9 10 \n",
"11 12 13 14 15 \n"
]
}
],
"source": [
"# Pattern 13\n",
"def nNumberTriangle(n: int) -> None:\n",
" num = 1\n",
" for i in range(n):\n",
" for _ in range(i+1):\n",
" print(num, end=' ')\n",
" num+=1\n",
" print()\n",
"\n",
"\n",
"nNumberTriangle(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,38 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pattern 14\n",
"\n",
"- pattern:\n",
"\n",
" ```text \n",
" n=3\n",
" 1\n",
" 0 1\n",
" 1 0 1\n",
" ```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 5715531

Please sign in to comment.