Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions bus/bus.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,52 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 34,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The number of stops is 9\n",
"The number of passengers at each stop: [10, 3, -2, -1, 4, -4, -3, -2, -1]\n",
"Maximum occupation of the bus is 14 passengers\n",
"Passengers in the bus: [10, 13, 11, 10, 14, 10, 7, 5, 4]\n",
"The average occupation is 9.333333333333334\n",
"The standart deviation is 3.391164991562634\n"
]
}
],
"source": [
"# variables\n",
"\n"
"import math\n",
"stops = [(10, 0), (4, 1), (3, 5), (3, 4), (5, 1), (1, 5), (5, 8 ), (4, 6), (2, 3)]\n",
"print('The number of stops is', len(stops))\n",
"passengers = []\n",
"for i in range(len(stops)):\n",
" n = stops[i][0] - stops[i][1]\n",
" passengers.append(n)\n",
"print('The number of passengers at each stop:', passengers)\n",
"maximum = 0\n",
"summ = 0\n",
"passengers_list = []\n",
"for j in range(len(passengers)):\n",
" summ += passengers[j]\n",
" passengers_list.append(summ)\n",
" if summ > maximum:\n",
" maximum = summ\n",
"print('Maximum occupation of the bus is {0} passengers'.format(maximum))\n",
"all_passengers = 0\n",
"for k in range(len(passengers_list)):\n",
" all_passengers += passengers_list[k]\n",
"average = all_passengers/len(passengers)\n",
"print('Passengers in the bus:', passengers_list)\n",
"print('The average occupation is', average)\n",
"numerator = 0\n",
"for n in range(len(passengers_list)):\n",
" numerator += (passengers_list[n] - average)**2\n",
"s2 = numerator/(len(passengers_list) - 1)\n",
"print('The standart deviation is', math.sqrt(s2))"
]
},
{
Expand Down Expand Up @@ -105,7 +145,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down
155 changes: 144 additions & 11 deletions duel/duel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,50 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The 0 clash is won by Saruman: 23 vs 10\n",
"The 1 clash is won by Saruman: 66 vs 11\n",
"The 2 clash wins Gandalf: 13 vs 12\n",
"The 3 clash is won by Saruman: 43 vs 30\n",
"The 4 clash wins Gandalf: 22 vs 12\n",
"The 5 clash wins Gandalf: 11 vs 10\n",
"The 6 clash is won by Saruman: 44 vs 10\n",
"The 7 clash wins Gandalf: 33 vs 23\n",
"The 8 clash wins Gandalf: 22 vs 12\n",
"The 9 clash wins Gandalf: 22 vs 17\n",
"Gandalf wins!!! The score is 6 vs 4\n"
]
}
],
"source": [
"# Assign spell power lists to variables\n",
"\n",
"gandalf = [10, 11, 13, 30, 22, 11, 10, 33, 22, 22]\n",
"saruman = [23, 66, 12, 43, 12, 10, 44, 23, 12, 17]"
"saruman = [23, 66, 12, 43, 12, 10, 44, 23, 12, 17]\n",
"gandalf_victory, saruman_victory = 0, 0\n",
"for i in range(len(gandalf)):\n",
" if gandalf[i] < saruman[i]:\n",
" print('The {0} clash is won by Saruman: {1} vs {2}'.format(i, saruman[i], gandalf[i]))\n",
" saruman_victory += 1\n",
" elif gandalf[i] > saruman[i]:\n",
" print('The {0} clash wins Gandalf: {1} vs {2}'.format(i, gandalf[i], saruman[i]))\n",
" gandalf_victory += 1\n",
" else:\n",
" print(\"It's a draw!!!\")\n",
" saruman_victory += 1\n",
" gandalf_victory += 1\n",
"if gandalf_victory > saruman_victory:\n",
" print('Gandalf wins!!! The score is {0} vs {1}'.format(gandalf_victory, saruman_victory))\n",
"elif saruman_victory > gandalf_victory:\n",
" print('Saruman wins!!! The score is {0} vs {1}'.format(saruman_victory, gandalf_victory))\n",
"else:\n",
" print(\"It's a draw!!! :)\")"
]
},
{
Expand All @@ -54,9 +90,21 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'gandalf' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-1-a0084d94601e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Execution of spell clashes\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgandalf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'gandalf' is not defined"
]
}
],
"source": [
"# Execution of spell clashes\n"
]
Expand Down Expand Up @@ -116,12 +164,37 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 40,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Gandalf: [50, 40, 40, 10, 50, 10, 40, 50, 10, 50]\n",
"Saruman: [45, 45, 25, 50, 25, 40, 10, 45, 10, 10]\n",
"The 0 clash wins Gandalf: 50 vs 45\n",
"The 1 clash is won by Saruman: 45 vs 40\n",
"The 2 clash wins Gandalf: 40 vs 25\n",
"The 3 clash is won by Saruman: 50 vs 10\n",
"The 4 clash wins Gandalf: 50 vs 25\n",
"The 5 clash is won by Saruman: 40 vs 10\n",
"The 6 clash wins Gandalf: 40 vs 10\n",
"The 7 clash wins Gandalf: 50 vs 45\n",
"It's a draw!!!\n",
"The 9 clash wins Gandalf: 50 vs 10\n",
"Gandalf wins!!!\n",
"Gandalf's average is 35.0\n",
"Saruman's average is 30.5\n",
"Gandalf's standart deviation is 17.795130420052185\n",
"Saruman's standart deviation is 17.07825127659933\n"
]
}
],
"source": [
"# 1. Spells now have a name and there is a dictionary that relates that name to a power.\n",
"# variables\n",
"import math\n",
"\n",
"POWER = {\n",
" 'Fireball': 50, \n",
Expand All @@ -134,16 +207,76 @@
"gandalf = ['Fireball', 'Lightning bolt', 'Lightning bolt', 'Magic arrow', 'Fireball', \n",
" 'Magic arrow', 'Lightning bolt', 'Fireball', 'Magic arrow', 'Fireball']\n",
"saruman = ['Contagion', 'Contagion', 'Black Tentacles', 'Fireball', 'Black Tentacles', \n",
" 'Lightning bolt', 'Magic arrow', 'Contagion', 'Magic arrow', 'Magic arrow']"
" 'Lightning bolt', 'Magic arrow', 'Contagion', 'Magic arrow', 'Magic arrow']\n",
"\n",
"gandalf2 = []\n",
"for i in gandalf:\n",
" gandalf2.append(POWER[i])\n",
"print('Gandalf:', gandalf2)\n",
"saruman2 = []\n",
"for i in saruman:\n",
" saruman2.append(POWER[i])\n",
"print('Saruman:', saruman2)\n",
"\n",
"#gandalf_victory, saruman_victory = 0, 0\n",
"winner = []\n",
"S = 'SSS'\n",
"G = 'GGG'\n",
"\n",
"for i in range(len(gandalf2)):\n",
" if gandalf2[i] < saruman2[i]:\n",
" print('The {0} clash is won by Saruman: {1} vs {2}'.format(i, saruman2[i], gandalf2[i]))\n",
" winner.append('S')\n",
" n = ''.join(winner)\n",
" if S in n:\n",
" print('Saruman wins!!!')\n",
" break\n",
" elif gandalf2[i] > saruman2[i]:\n",
" print('The {0} clash wins Gandalf: {1} vs {2}'.format(i, gandalf2[i], saruman2[i]))\n",
" winner.append('G')\n",
" n = ''.join(winner)\n",
" if G in n:\n",
" print('Gandalf wins!!!')\n",
" break\n",
" else:\n",
" print(\"It's a draw!!!\")\n",
"average_G = sum(gandalf2)/len(gandalf2)\n",
"print(\"Gandalf's average is\", average_G)\n",
"average_S = sum(saruman2)/len(saruman2)\n",
"print(\"Saruman's average is\", average_S)\n",
"\n",
"numerator = 0\n",
"for n in range(len(gandalf2)):\n",
" numerator += (gandalf2[n] - average_G)**2\n",
"s2G = numerator/(len(gandalf2) - 1)\n",
"print(\"Gandalf's standart deviation is\", math.sqrt(s2G))\n",
"numerator = 0\n",
"for n in range(len(saruman2)):\n",
" numerator += (saruman2[n] - average_G)**2\n",
"s2S = numerator/(len(saruman2) - 1)\n",
"print(\"Saruman's standart deviation is\", math.sqrt(s2S))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'POWER' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-5-0994f0ebb33e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Assign spell power lists to variables\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mgandalf2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mPOWER\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'POWER' is not defined"
]
}
],
"source": [
"# Assign spell power lists to variables\n",
"\n",
"\n"
]
},
Expand Down Expand Up @@ -210,7 +343,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down
64 changes: 59 additions & 5 deletions robin-hood/robin-hood.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,70 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 37,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Q1 have 11 arrows,\n",
"Q2 have 6 arrows,\n",
"Q3 have 2 arrows,\n",
"Q4 have 3 arrows\n",
"All distances from the center are:\n",
" [6.4031242374328485, 2.0, 8.06225774829855, 3.1622776601683795, 3.605551275463989, 6.4031242374328485, 3.605551275463989, 8.602325267042627, 8.602325267042627, 2.8284271247461903, 6.4031242374328485, 2.0, 8.06225774829855, 3.1622776601683795, 3.605551275463989, 6.4031242374328485, 3.605551275463989, 8.602325267042627, 8.602325267042627, 2.8284271247461903, 12.727922061357855, 12.041594578792296]\n",
"The shortest distance is 2.0\n",
"2 arrows fly away...\n"
]
},
{
"data": {
"text/plain": [
"'a = -0\\nprint(a)\\nprint(a*2)\\nprint(0 == -0)\\nprint(-0/5)'"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Variables\n",
"\n",
"import math\n",
"points = [(4, 5), (-0, 2), (4, 7), (1, -3), (3, -2), (4, 5),\n",
" (3, 2), (5, 7), (-5, 7), (2, 2), (-4, 5), (0, -2),\n",
" (-4, 7), (-1, 3), (-3, 2), (-4, -5), (-3, 2),\n",
" (5, 7), (5, 7), (2, 2), (9, 9), (-8, -9)]"
" (5, 7), (5, 7), (2, 2), (9, 9), (-8, -9)]\n",
"q1, q2, q3, q4 = 0, 0, 0, 0\n",
"for i in range(len(points)):\n",
" if points[i][0] >= 0 and points[i][1] >= 0:\n",
" q1 += 1\n",
" elif points[i][0] < 0 and points[i][1] < 0:\n",
" q3 += 1\n",
" elif points[i][0] >= 0 and points[i][1] < 0:\n",
" q4 += 1\n",
" else:\n",
" q2 += 1\n",
"print('Q1 have {0} arrows,\\nQ2 have {1} arrows,\\nQ3 have {2} arrows,\\nQ4 have {3} arrows'.format(q1, q2, q3, q4))\n",
"minimum = True\n",
"lengths = []\n",
"for j in range(len(points)):\n",
" d = math.sqrt((points[j][0])**2 + (points[j][1])**2)\n",
" lengths.append(d)\n",
"print('All distances from the center are:\\n', lengths)\n",
"print('The shortest distance is', min(lengths))\n",
"number = 0\n",
"for k in range(len(lengths)):\n",
" if lengths[k] > 9:\n",
" number += 1\n",
"print(number, 'arrows fly away...')\n",
"\n",
"'''a = -0\n",
"print(a)\n",
"print(a*2)\n",
"print(0 == -0)\n",
"print(-0/5)'''"
]
},
{
Expand Down Expand Up @@ -121,7 +175,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down
Empty file added robot.md
Empty file.
Loading