Skip to content

Commit

Permalink
saving all popcorn hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
leila010 committed Nov 13, 2024
1 parent 691a356 commit 2b34e34
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 24 deletions.
105 changes: 100 additions & 5 deletions _notebooks/Iteration/2024-11-2-iteration-homework.ipynb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"cell_type": "raw",
"metadata": {
"vscode": {
"languageId": "yaml"
"languageId": "raw"
}
},
"outputs": [],
"source": [
"---\n",
"comments: True\n",
Expand Down Expand Up @@ -53,6 +51,89 @@
"**Optional**: use console.error() to report an error if the board is illegal (ex. 7 \"X\"s and 2 \"O\"s)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"vscode": {
"languageId": "javascript"
}
},
"outputs": [
{
"data": {
"application/javascript": "let board = [\n [\"X\", \"None\", \"O\"],\n [\"X\", \"O\", \"None\"],\n [\"O\", \"None\", \"X\"]\n ];\n \n function countMoves(symbol) {\n let count = 0;\n for (let row of board) {\n for (let cell of row) {\n if (cell === symbol) {\n count++;\n }\n }\n }\n return count;\n }\n \n function determineTurn() {\n let xCount = countMoves(\"X\");\n let oCount = countMoves(\"O\");\n \n if (xCount < oCount || xCount > oCount + 1) {\n console.error(\"Error: Invalid board state. The number of 'X' and 'O' moves is incorrect.\");\n return;\n }\n \n if (xCount === oCount) {\n console.log(\"It's Player X's turn.\");\n } else if (xCount > oCount) {\n console.log(\"It's Player O's turn.\");\n }\n }\n \n determineTurn();\n \n let outerFactor = 1; \n \n while (outerFactor <= 10) {\n let innerFactor = 1; \n \n let rowOutput = \"\";\n \n while (innerFactor <= 10) {\n let product = outerFactor * innerFactor;\n \n rowOutput += product + \"\\t\";\n \n innerFactor++;\n }\n \n\n console.log(rowOutput);\n \n \n outerFactor++;\n }\n \n\n",
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%js \n",
"let board = [\n",
" [\"X\", \"None\", \"O\"],\n",
" [\"X\", \"O\", \"None\"],\n",
" [\"O\", \"None\", \"X\"]\n",
" ];\n",
" \n",
" function countMoves(symbol) {\n",
" let count = 0;\n",
" for (let row of board) {\n",
" for (let cell of row) {\n",
" if (cell === symbol) {\n",
" count++;\n",
" }\n",
" }\n",
" }\n",
" return count;\n",
" }\n",
" \n",
" function determineTurn() {\n",
" let xCount = countMoves(\"X\");\n",
" let oCount = countMoves(\"O\");\n",
" \n",
" if (xCount < oCount || xCount > oCount + 1) {\n",
" console.error(\"Error: Invalid board state. The number of 'X' and 'O' moves is incorrect.\");\n",
" return;\n",
" }\n",
" \n",
" if (xCount === oCount) {\n",
" console.log(\"It's Player X's turn.\");\n",
" } else if (xCount > oCount) {\n",
" console.log(\"It's Player O's turn.\");\n",
" }\n",
" }\n",
" \n",
" determineTurn();\n",
" \n",
" let outerFactor = 1; \n",
" \n",
" while (outerFactor <= 10) {\n",
" let innerFactor = 1; \n",
" \n",
" let rowOutput = \"\";\n",
" \n",
" while (innerFactor <= 10) {\n",
" let product = outerFactor * innerFactor;\n",
" \n",
" rowOutput += product + \"\\t\";\n",
" \n",
" innerFactor++;\n",
" }\n",
" \n",
"\n",
" console.log(rowOutput);\n",
" \n",
" \n",
" outerFactor++;\n",
" }\n",
" \n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -87,8 +168,22 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
46 changes: 41 additions & 5 deletions _notebooks/Iteration/2024-11-2-iteration-p1.ipynb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"cell_type": "raw",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"comments: True\n",
Expand Down Expand Up @@ -166,6 +168,40 @@
"\n",
"**Hint**: Any number divided by two results in a remainder of 1 for odd numbers and 0 for even numbers. The modulo operator (`%`) helps you determine this condition. The statement `if (n % 2 == 0)` would be true when `n` is even."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"vscode": {
"languageId": "javascript"
}
},
"outputs": [
{
"data": {
"application/javascript": "\nlet sum = 0;\n\nfor (let i = 1; i <= 20; i++) {\n if (i % 2 === 0) {\n sum += i;\n }\n}\n\nconsole.log(\"The sum of all even numbers from 1 to 20 is: \" + sum);\n",
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%js\n",
"\n",
"let sum = 0;\n",
"\n",
"for (let i = 1; i <= 20; i++) {\n",
" if (i % 2 === 0) {\n",
" sum += i;\n",
" }\n",
"}\n",
"\n",
"console.log(\"The sum of all even numbers from 1 to 20 is: \" + sum);\n"
]
}
],
"metadata": {
Expand All @@ -184,7 +220,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.5"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
10 changes: 6 additions & 4 deletions _notebooks/Iteration/2024-11-5-iteration-p2.ipynb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"cell_type": "raw",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"comments: True\n",
Expand Down
69 changes: 59 additions & 10 deletions _notebooks/Iteration/2024-11-7-Iteration-P3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"execution_count": 4,
"metadata": {
"vscode": {
"languageId": "javascript"
}
},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -86,7 +90,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {
"vscode": {
"languageId": "javascript"
Expand All @@ -95,7 +99,7 @@
"outputs": [
{
"data": {
"application/javascript": "// Initialize a variable\nlet counter = 0;\n\n// While loop starts\nwhile (counter <= 10) {\n console.log(\"Counter is: \" + counter);\n counter++;\n}\n",
"application/javascript": "// Initialize the counter\nlet counter = 0;\n\n// While loop starts\nwhile (counter < 5) { \n console.log(\"Counter is: \" + counter);\n counter++; \n}\n",
"text/plain": [
"<IPython.core.display.Javascript object>"
]
Expand All @@ -106,14 +110,14 @@
],
"source": [
"%%js\n",
"// Initialize a variable\n",
"// Initialize the counter\n",
"let counter = 0;\n",
"\n",
"// While loop starts\n",
"while (counter <= 10) {\n",
"while (counter < 5) { \n",
" console.log(\"Counter is: \" + counter);\n",
" counter++;\n",
"}"
" counter++; \n",
"}\n"
]
},
{
Expand Down Expand Up @@ -168,6 +172,51 @@
"Increment outerFactor by 1 to move to the next row in the table."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"vscode": {
"languageId": "javascript"
}
},
"outputs": [
{
"data": {
"application/javascript": "\n\nlet outerFactor = 1;\n\nwhile (outerFactor <= 10) {\n let innerFactor = 1;\n\n let rowOutput = \"\";\n\n while (innerFactor <= 10) {\n let product = outerFactor * innerFactor;\n\n rowOutput += product + \"\\t\";\n\n innerFactor++;\n }\n\n console.log(rowOutput);\n\n outerFactor++;\n}\n",
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%js\n",
"\n",
"\n",
"let outerFactor = 1;\n",
"\n",
"while (outerFactor <= 10) {\n",
" let innerFactor = 1;\n",
"\n",
" let rowOutput = \"\";\n",
"\n",
" while (innerFactor <= 10) {\n",
" let product = outerFactor * innerFactor;\n",
"\n",
" rowOutput += product + \"\\t\";\n",
"\n",
" innerFactor++;\n",
" }\n",
"\n",
" console.log(rowOutput);\n",
"\n",
" outerFactor++;\n",
"}\n"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand All @@ -182,7 +231,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "venv",
"language": "python",
"name": "python3"
},
Expand All @@ -196,7 +245,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 2b34e34

Please sign in to comment.