-
-
Save kylebgorman/b05432e33ec102c1e376d70123db23b3 to your computer and use it in GitHub Desktop.
Methods I HW2 solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "69e72cc6", | |
"metadata": {}, | |
"source": [ | |
"# Part 1" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "805fbabe", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"a is in manhattan\n", | |
"o is in brooklyn\n", | |
"e is in queens\n", | |
"u is in queens\n", | |
"e is in the bronx\n", | |
"o is in the bronx\n", | |
"a is in staten island\n", | |
"e is in staten island\n", | |
"i is in staten island\n" | |
] | |
} | |
], | |
"source": [ | |
"boroughs = [\"manhattan\", \"brooklyn\", \"queens\",\n", | |
" \"the bronx\", \"staten island\"]\n", | |
"vowels = [\"a\", \"e\", \"i\", \"o\", \"u\"]\n", | |
"for borough in boroughs:\n", | |
" for vowel in vowels:\n", | |
" if vowel in borough:\n", | |
" # A fancier style: print(f\"{vowel} is in {borough}\")\n", | |
" print(vowel + \" is in \" + borough)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "55260ad1", | |
"metadata": {}, | |
"source": [ | |
"# Part 2" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "bda1d5b2", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"1\n", | |
"8\n", | |
"27\n", | |
"64\n", | |
"125\n", | |
"216\n", | |
"343\n", | |
"512\n", | |
"729\n" | |
] | |
} | |
], | |
"source": [ | |
"for x in range(1, 10):\n", | |
" xcube = x * x * x\n", | |
" print(xcube)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "a27acfc9", | |
"metadata": {}, | |
"source": [ | |
"The _cool numbers_ are more properly known as _perfect cubes_." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "168dd72a", | |
"metadata": {}, | |
"source": [ | |
"# Stretch goal" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "ee6523f4", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"9\n", | |
"28\n", | |
"65\n", | |
"126\n", | |
"217\n", | |
"344\n", | |
"513\n", | |
"730\n", | |
"35\n", | |
"72\n", | |
"133\n", | |
"224\n", | |
"351\n", | |
"520\n", | |
"737\n", | |
"91\n", | |
"152\n", | |
"243\n", | |
"370\n", | |
"539\n", | |
"756\n", | |
"189\n", | |
"280\n", | |
"407\n", | |
"576\n", | |
"793\n", | |
"341\n", | |
"468\n", | |
"637\n", | |
"854\n", | |
"559\n", | |
"728\n", | |
"945\n", | |
"855\n" | |
] | |
} | |
], | |
"source": [ | |
"# Ideally we'd print these in order.\n", | |
"for x in range(1, 10):\n", | |
" xcube = x * x * x\n", | |
" for y in range(x + 1, 10):\n", | |
" ycube = y * y * y\n", | |
" z = xcube + ycube\n", | |
" # Hackish. There's a better solution.\n", | |
" if z >= 1000:\n", | |
" continue\n", | |
" print(z)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "9da81590", | |
"metadata": {}, | |
"source": [ | |
"The _hip numbers_ can be used to define what are known as the [_Ramanujan numbers_, _Ramanujan-Hardy numbers_, or _taxicab numbers_](https://en.wikipedia.org/wiki/Taxicab_number). According to legend, the mathematician Ramanujan was told that his visitor had taken a taxicab with this number and observed that it was the smallest counting number that was the sum of two different cubes (i.e., \"hip\" in two ways)." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "26d2e56e", | |
"metadata": {}, | |
"source": [ | |
"# Reflection" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "b88ac941", | |
"metadata": {}, | |
"source": [ | |
"Your reflection here." | |
] | |
} | |
], | |
"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.9.13" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment