355 lines
44 KiB
Plaintext
355 lines
44 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 128,
|
||
|
"id": "e4365f4a-71af-4b54-8000-e549c34df127",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"%matplotlib inline\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"import numpy as np\n",
|
||
|
"from ipywidgets import interactive, fixed\n",
|
||
|
"from IPython import display\n",
|
||
|
"from random import randint\n",
|
||
|
"from time import sleep\n",
|
||
|
"from sympy import symbols, Eq\n",
|
||
|
"from sympy.solvers import solve\n",
|
||
|
"from sympy.parsing.sympy_parser import parse_expr"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "23fa0780-17a8-4801-ae5a-f4ee0172ae40",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Projectile game"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "0740f36c-6c52-422f-9db0-a6619a9a5ffb",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Easy Mode"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 116,
|
||
|
"id": "f39607ff-7776-4d49-8de9-2f79bff89a92",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"application/vnd.jupyter.widget-view+json": {
|
||
|
"model_id": "6016d1e3623c4376bcf7aa7041f2beaf",
|
||
|
"version_major": 2,
|
||
|
"version_minor": 0
|
||
|
},
|
||
|
"text/plain": [
|
||
|
"interactive(children=(FloatSlider(value=0.0, description='a', max=25.0, min=-25.0), FloatSlider(value=0.0, des…"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 116,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"xlo = -2\n",
|
||
|
"xhi = 20\n",
|
||
|
"ylo = -20\n",
|
||
|
"yhi = 120\n",
|
||
|
"\n",
|
||
|
"def graph(a, b, c, height, distance):\n",
|
||
|
" plt.clf()\n",
|
||
|
" fix = plt.subplot()\n",
|
||
|
" plt.axis([xlo, xhi, ylo, yhi])\n",
|
||
|
" plt.plot([0, 0], [ylo, yhi], \"black\")\n",
|
||
|
" plt.plot([xlo, xhi], [0, 0], \"black\")\n",
|
||
|
" wall_height = height\n",
|
||
|
" wall_distance = distance\n",
|
||
|
" plt.plot([wall_distance, wall_distance], [0, wall_height], \"brown\")\n",
|
||
|
" plt.grid()\n",
|
||
|
" plt.title(f\"{a:.1f}*x**2 + {b:.1f}*x + {c:.1f}\")\n",
|
||
|
" \n",
|
||
|
" x = np.linspace(0, xhi, xhi*1000)\n",
|
||
|
" y = a*x**2 + b*x + c\n",
|
||
|
" success = a*wall_distance**2 + b*wall_distance + c > wall_height\n",
|
||
|
" x2 = []\n",
|
||
|
" y2 = []\n",
|
||
|
" for i in range(len(y)):\n",
|
||
|
" if y[i] < 0:\n",
|
||
|
" break\n",
|
||
|
" if not success and x[i] > wall_distance:\n",
|
||
|
" break\n",
|
||
|
" x2.append(x[i])\n",
|
||
|
" y2.append(y[i])\n",
|
||
|
" \n",
|
||
|
" y2[-1] = 0 # finally ball hits the ground (handling imprecisions and ball hitting walls)\n",
|
||
|
" plt.plot([x2[-1]], [y2[-1]], 'ro')\n",
|
||
|
" plt.plot(x2, y2, \"b\")\n",
|
||
|
" plt.show()\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"slider_range = (-25, 25, 0.1)\n",
|
||
|
"wall_height = randint(2, yhi-20)\n",
|
||
|
"wall_distance = randint(2, xhi-2)\n",
|
||
|
"interactive_graph = interactive(graph, a=slider_range, b=slider_range, c=slider_range, height=fixed(wall_height), distance=fixed(wall_distance))\n",
|
||
|
"interactive_graph"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "810b43cb-8289-4952-8259-648add3bbb0e",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Hard Mode\n",
|
||
|
"Now guess projectile paramaters without fiddloing with slider"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 127,
|
||
|
"id": "8b65fbea-7647-4e29-902e-ddd80170cdc8",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjoAAAGzCAYAAAAmH71NAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9hAAAPYQGoP6dpAABNtklEQVR4nO3dd3xT9foH8E+6Bx20QAdQKIgUEZBt2aO0qEgRrlgsCoKA2KpQZXnZqxSQKQLey7gqMryXcRUvWMqWskERoQKWTQsWu1faPr8/8mtsSDdJ0xw+79crL5Jzvjl5npyk+XByco5KRARERERECmRh6gKIiIiIjIVBh4iIiBSLQYeIiIgUi0GHiIiIFItBh4iIiBSLQYeIiIgUi0GHiIiIFItBh4iIiBSLQYeIiIgUi0GHiEihrl+/DpVKhY0bN2qnzZw5EyqVqlz3V6lUmDlzpnGKU4CDBw9CpVLh3//+t8GXvXDhQvj5+aGgoMDgy37SMOiYiYsXL2Lo0KGoW7cubG1t4e3tjdDQUFy8eNHUpRlMTEwMRowYgaeffhoODg5o1KgR3n77bdy7d6/cy7hz5w4GDx4MV1dXODs7Izg4GL///nuJ4xs2bGiAyoEePXrg+vXrJc7fuHFjsR8Yt27dwqxZs9ChQwfUrFkTtWrVQo8ePbBv3z6D1FVRq1evxquvvgofHx+oVCoMHz68xLFnzpxBv3794OnpiRo1aqBly5ZYsWIF8vPzy/VYly5dQt++fVGjRg24ubnhjTfewIMHD4ode/36dfTo0aMSHVWduLg4jB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OHDh4udXxgExowZozP97Nmz0rdvX3FychJHR0fp1auXxMbG6ozZsGGDAJBDhw7J6NGjxc3NTZycnOSNN96Qhw8f6ow9deqUBAYGiru7u9jZ2UnDhg3lrbfeMmyzJXBzc5OBAweWOa59+/bSvn17vemBgYHSuHFjnWk7d+6U5557TmxsbOT555+XI0eOaOfFxMSISqWSadOm6dxn06ZNAkA+++wz7bSffvpJAgICxN7eXp566inZsGGDTlhKTU2VKVOmiLu7uzg7O8s777yjF2yKExERIQC0H5wV8ThBp6jSgs5rr70mzs7OesH0tddeEw8PjzKXXadOHXn11Vf1pj/99NPSu3dv7e38/HxZv369PPXUU2Jvby99+vSRCxcuaOevX79eAMi6det0ljNv3jwBILt37y6zlqIeJ+gU9ThBJy8vT1JSUir8mH/++acMGzZMnJ2dxcXFRd588005d+6cXtCZMWOGXojIzs6WcePGSa1ataRGjRry8ssvy61bt8oVdAo/7Ldu3Spz586VunXriq2trfTq1UuuXLmiN37btm3Spk0bsbOzE3d3dwkNDZXbt2/rPA8A9C4lGT9+vLi5uem878LDwwWALF++XDstISFB7/2bmJgoI0aMkDp16oitra20bNlSNm7cqLP8wtfEokWLZOnSpdKoUSOxsLCQc+fOFRt0srOz5aWXXhJnZ2f58ccfS33ubty4IZcuXdKZ9vvvvwsAvTqo8vjVVTX37bffomHDhujatWux87t164aGDRti9+7d2mkXL15E165d8dNPP2HixImYNm0a4uPj0aNHD5w4cUJvGeHh4bh06RJmzpyJN998E5s2bcKAAQMgIgCA+/fvIzAwENevX8fkyZOxcuVKhIaG4vjx48Zpuoj09HSkp6ejVq1apY4rKCjAzz//jHbt2unN69ChA65du4a0tDTtNAsLC50dMote79WrF959911ERkbi7NmzAIB79+7hvffeQ0BAAN55551il1O4T0VRFhYWOt+xl3cn0ISEBDg4OMDBwaFc46tajx49kJqaijFjxuDSpUu4ceMG1qxZg+3bt2PKlCml3vfOnTu4f/9+ievq3Llz2tsqlUrv+Sv6HL711lvo168fIiIicOvWLQDAhQsXMGvWLIwcORIvvvji47ZapTIzM+Hs7AwXFxe4ubkhLCwM6enpZd5PRBAcHIwvv/wSQ4cOxdy5c3H79m0MGzasXI/79ttvY9myZQgMDMSCBQtgbW2Nl156qUK1L1iwADt27MBHH32EKVOm4Pjx4wgNDdUZs3HjRgwePBiWlpaIjIzEqFGjsH37dnTp0gXJyckAgDFjxqBPnz4AoPMVXkm6du2Khw8f6uyveOTIEVhYWODIkSM60wDN30wAyMrKQo8ePfDll18iNDQUixYtgouLC4YPH47ly5frPc6GDRuwcuVKjB49Gp988gnc3Nz0xmRlZeHll1/GsWPHsG/fPnTq1KnU5+zNN9/U+5rz2LFjAIA2bdqUel+qAFMnLSpZcnKyAJDg4OBSx/Xv31/nf/8DBgwQGxsbna+z7t69K05OTtKtWzfttMItOm3btpXc3Fzt9IULFwoA2bVrl4iI7NixQwDIqVOnDNhd+cyZM0cASExMTKnjHjx4IABk9uzZevNWrVolAOTy5cuSlpYmffr0kT59+sjvv/+u89XV66+/rv1fYUZGhjz11FPSvHlznf+hFf2qZcKECXpfXQ0ZMkT71dWBAwfE19dXZs+erf3q6rPPPtP56qo4V65cETs7O3njjTcq9ZxVxRadvLw8CQ8PF2tra+3/uC0tLWX16tVlLvfUqVMCQL744gu9eRMmTBAAkp2dLbdv35Z27drJkCFDdL668vPzkwkTJmjvc+/ePXFzc5M+ffpITk6OtG7dWnx8fCq1VcSUW3QmT54skyZNkq1bt8rmzZu1WzY6d+4sarW61Pvu3LlTAMjChQu10/Ly8qRr165lbtE5f/68AJB3331XZ5mvv/56hbboNGvWTHJycrTTly9fLgC0W+Byc3OlTp068uyzz0pWVpZ23HfffScAZPr06dppFfnq6v79+zpbapKTk8XCwkJeffVVna2L77//vs6Wn2XLlgkA+eqrr7RjcnNzxd/fX2rUqKH9e1r4mnB2dtbbfaDoFp20tDTp3r271Kp
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"xlo = -2\n",
|
||
|
"xhi = 20\n",
|
||
|
"ylo = -20\n",
|
||
|
"yhi = 120\n",
|
||
|
"\n",
|
||
|
"wall_height = randint(2, yhi-20)\n",
|
||
|
"wall_distance = randint(2, xhi-2)\n",
|
||
|
"\n",
|
||
|
"plt.clf()\n",
|
||
|
"fix = plt.subplot()\n",
|
||
|
"plt.axis([xlo, xhi, ylo, yhi])\n",
|
||
|
"plt.plot([0, 0], [ylo, yhi], \"black\")\n",
|
||
|
"plt.plot([xlo, xhi], [0, 0], \"black\")\n",
|
||
|
"plt.plot([wall_distance, wall_distance], [0, wall_height], \"brown\")\n",
|
||
|
"plt.grid()\n",
|
||
|
"display.display(plt.gcf())\n",
|
||
|
"\n",
|
||
|
"print(\"You're at origin, provide A, B and C values for projectile to get across wall.\")\n",
|
||
|
"a = float(input(\"A: \"))\n",
|
||
|
"b = float(input(\"B: \"))\n",
|
||
|
"c = float(input(\"C: \"))\n",
|
||
|
"\n",
|
||
|
"x = np.linspace(0, xhi, xhi*1000)\n",
|
||
|
"y = a*x**2 + b*x + c\n",
|
||
|
"success = a*wall_distance**2 + b*wall_distance + c > wall_height\n",
|
||
|
"x2 = []\n",
|
||
|
"y2 = []\n",
|
||
|
"for i in range(len(y)):\n",
|
||
|
" if y[i] < 0:\n",
|
||
|
" break\n",
|
||
|
" if not success and x[i] > wall_distance:\n",
|
||
|
" break\n",
|
||
|
" x2.append(x[i])\n",
|
||
|
" y2.append(y[i])\n",
|
||
|
"\n",
|
||
|
"if success:\n",
|
||
|
" plt.title(f\"Awesome, {a:.1f}*x**2 + {b:.1f}*x + {c:.1f} worked!\")\n",
|
||
|
"else:\n",
|
||
|
" plt.title(f\"Oops, {a:.1f}*x**2 + {b:.1f}*x + {c:.1f} did not work :(\")\n",
|
||
|
" y2[-1] = 0 # ball hits the ground after hitting wall\n",
|
||
|
"\n",
|
||
|
"plt.plot([x2[-1]], [y2[-1]], 'ro')\n",
|
||
|
"plt.plot(x2, y2, \"b\")\n",
|
||
|
"display.clear_output(wait=True)\n",
|
||
|
"plt.show()\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "5ef5840e-9c5a-41b0-8f79-2588f6915f78",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Algebra practice game "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 144,
|
||
|
"id": "56df3e31-3cfe-47b8-bde5-2096cff8d941",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Solve for x in following equation:\n",
|
||
|
"34 - x / 18 = -49\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"name": "stdin",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"answer: 1494\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Pretty accurate!\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"def rn(): # random integer\n",
|
||
|
" return randint(-100, 100)\n",
|
||
|
"\n",
|
||
|
"def rop(): # random operation\n",
|
||
|
" op = randint(1, 4)\n",
|
||
|
" if op == 1:\n",
|
||
|
" return '+'\n",
|
||
|
" elif op == 2:\n",
|
||
|
" return '-'\n",
|
||
|
" elif op == 3:\n",
|
||
|
" return '*'\n",
|
||
|
" elif op == 4:\n",
|
||
|
" return '/'\n",
|
||
|
"\n",
|
||
|
"def rpm(): # random plus minus\n",
|
||
|
" if randint(0, 1):\n",
|
||
|
" return '-'\n",
|
||
|
" return ''\n",
|
||
|
"\n",
|
||
|
"x = symbols(\"x\")\n",
|
||
|
"\n",
|
||
|
"eq = \"\"\n",
|
||
|
"if randint(0, 1): # one step problem\n",
|
||
|
" eq = f\"x {rop()} {rn()} = {rn()}\"\n",
|
||
|
"else:\n",
|
||
|
" eq = f\"{rn()} {rop()} {rpm()}x {rop()} {rn()} = {rn()}\"\n",
|
||
|
"eq = eq.replace('- -', '+ ').replace('+ -', '- ').replace('- +=', '- ')\n",
|
||
|
"lhs, rhs = [parse_expr(part) for part in eq.split(' = ')]\n",
|
||
|
"sympy_eq = Eq(lhs, rhs)\n",
|
||
|
"\n",
|
||
|
"solution = round(solve(sympy_eq, x)[0], 2)\n",
|
||
|
"\n",
|
||
|
"print(\"Solve for x in following equation:\")\n",
|
||
|
"print(eq)\n",
|
||
|
"ans = [float(num) for num in input(\"answer: \").split('/')]\n",
|
||
|
"if len(ans) == 2:\n",
|
||
|
" ans = ans[0]/ans[1]\n",
|
||
|
"else:\n",
|
||
|
" ans = ans[0]\n",
|
||
|
"\n",
|
||
|
"if abs(ans-solution) < 0.01:\n",
|
||
|
" print(\"Pretty accurate!\")\n",
|
||
|
"else:\n",
|
||
|
" print(f\"Oops! correct answer was {solution} but your answer was {ans}\")\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "4354b487-229b-40b3-92e9-74610bc74030",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Scatter Plot Game "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 146,
|
||
|
"id": "4dac8ed5-b7dd-42d5-a4ed-e51af3324867",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAioAAAGdCAYAAAA8F1jjAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAZMklEQVR4nO3df2xV9d3A8U/50SKDXn7aDimKPyLbjBpBtDrYnISa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pic7OziN+TXNzc+RyueJWV1fXH6MCAGVQ9h/9HK+mpqbI5/PFrb29vdwjAQAlMqycf/iECRNi6NCh0dXV1We9q6sramtrj/g1VVVVUVVV1R/jAQBlVtZXVCorK2P69OmxcePG4lpvb29s3Lgx6uvryzgZAJCCsr6iEhGxdOnS+PrXvx4zZsyImTNnxve+973Yv39/3HDDDeUeDQAos7KHype//OV4991346677orOzs648MIL45e//OVhN9gCACefiizLsnIP8XEUCoXI5XKRz+ejurq63OMAAMfgWJ+/B9y7fgCAk4dQAQCSJVQAgGQJFQAgWUIFAEiWUAEAkiVUAIBkCRUAIFlCBQBIllABAJIlVACAZAkVACBZQgUASJZQAQCSJVQAgGQJFQAgWUIFAEiWUAEAkiVUAIBkCRUAIFlCBQBIllABAJIlVACAZAkVACBZQgUASJZQAQCSJVQAgGQJFQAgWUIFAEiWUAEAkiVUAIBkCRUAIFlCBQBIllABAJIlVACAZAkVACBZQgU
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"name": "stdin",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Guess the location of point (x, y) on graph: -28, 22\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Sorry, the correct answer was (-25, 24) but you provided (-28, 22)\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.clf()\n",
|
||
|
"xlo = -50\n",
|
||
|
"xhi = 50\n",
|
||
|
"ylo = -50\n",
|
||
|
"yhi = 50\n",
|
||
|
"\n",
|
||
|
"x = randint(xlo, xhi)\n",
|
||
|
"y = randint(ylo, yhi)\n",
|
||
|
"\n",
|
||
|
"fig = plt.subplot()\n",
|
||
|
"plt.axis([xlo, xhi, ylo, yhi])\n",
|
||
|
"plt.plot([x], [y], 'ro')\n",
|
||
|
"plt.show()\n",
|
||
|
"\n",
|
||
|
"gussed_x, gussed_y = [int(round(float(num.strip(' ')), 0)) for num in input(\"Guess the location of point (x, y) on graph: \").split(', ')]\n",
|
||
|
"\n",
|
||
|
"if gussed_x == x and gussed_y == y:\n",
|
||
|
" print(\"You got it!\")\n",
|
||
|
"else:\n",
|
||
|
" print(f\"Sorry, the correct answer was ({x}, {y}) but you provided ({gussed_x}, {gussed_y})\")"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "8d9745ef-fe26-477f-a480-e146542b04c1",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3 (ipykernel)",
|
||
|
"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.8.10"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 5
|
||
|
}
|