"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## We just discovered two possible \"algorithms\" to solve this problem: \n",
"### Option 1: Always sending the fastest person\n",
"### Option 2: Combining the two slowest people"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def CalculateTime(A, B, C, D):\n",
" t=[A,B,C,D]\n",
" t.sort()\n",
" A=t[0] \n",
" B=t[1] \n",
" C=t[2] \n",
" D=t[3]\n",
" print('Sending Fastest Person solves the problem in', B+A+C+A+D, 'minutes')\n",
" print('Combining Two Slowest solves the problem in', B+A+D+B+B, 'minutes')\n",
" return"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Let's compare our algorithms, and see which one is faster.\n",
"### Let's experiment by trying different input values for A, B, C, and D."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "90f2f7fb24c8459c8c05317ff7e58a3a",
"version_major": 2,
"version_minor": 0
},
"text/html": [
"Failed to display Jupyter Widget of type interactive
.
\n",
"\n",
" If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n",
" that the widgets JavaScript is still loading. If this message persists, it\n",
" likely means that the widgets JavaScript library is either not installed or\n",
" not enabled. See the Jupyter\n",
" Widgets Documentation for setup instructions.\n",
"
\n",
"\n",
" If you're reading this message in another frontend (for example, a static\n",
" rendering on GitHub or NBViewer),\n",
" it may mean that your frontend doesn't currently support widgets.\n",
"
\n"
],
"text/plain": [
"interactive(children=(IntSlider(value=1, description='A', max=20, min=1), IntSlider(value=1, description='B', max=20, min=1), IntSlider(value=1, description='C', max=20, min=1), IntSlider(value=1, description='D', max=20, min=1), Output()), _dom_classes=('widget-interact',))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from ipywidgets import interact\n",
"import ipywidgets as widgets\n",
"interact(CalculateTime,\n",
"A=widgets.IntSlider(min=1, max=20),\n",
"B=widgets.IntSlider(min=1, max=20),\n",
"C=widgets.IntSlider(min=1, max=20),\n",
"D=widgets.IntSlider(min=1, max=20))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Two Challenge Questions\n",
"### For which values of (A,B,C,D) do the above solutions result in the same total time?\n",
"### How many different ways can the four people cross the bridge? (Hint: the answer is more than 100!)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![alt text](https://github.com/callysto/callysto-sample-notebooks/blob/master/notebooks/images/Callysto_Notebook-Banners_Bottom_06.06.18.jpg?raw=true)"
]
}
],
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}