Added some further ipython solutions.
This commit is contained in:
@@ -10,31 +10,41 @@
|
||||
"\n",
|
||||
"$2^2=4, 2^3=8, 2^4=16, 2^5=32$\n",
|
||||
"\n",
|
||||
"32=9, 33=27, 34=81, 35=243\n",
|
||||
"$3^2=9, 3^3=27, 3^4=81, 3^5=243$\n",
|
||||
"\n",
|
||||
"42=16, 43=64, 44=256, 45=1024\n",
|
||||
"$4^2=16, 4^3=64, 4^4=256, 4^5=1024$\n",
|
||||
"\n",
|
||||
"52=25, 53=125, 54=625, 55=3125\n",
|
||||
"$5^2=25, 5^3=125, 5^4=625, 5^5=3125$\n",
|
||||
"\n",
|
||||
"If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms:\n",
|
||||
"\n",
|
||||
"4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125\n",
|
||||
"$4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125$\n",
|
||||
"\n",
|
||||
"How many distinct terms are in the sequence generated by ab for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?"
|
||||
"How many distinct terms are in the sequence generated by $a^b$ for $2 ≤ a ≤ 100$ and $2 ≤ b ≤ 100$?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"9183\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"s = len(set([a**b for a in range(2, 101) for b in range(2, 101)]))\n",
|
||||
"assert(s == 9183)\n",
|
||||
"print(s)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"comopletion_date": "",
|
||||
"comopletion_date": "Fri, 25 Aug 2017, 10:03",
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
@@ -52,7 +62,10 @@
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.6.3"
|
||||
},
|
||||
"tags": []
|
||||
"tags": [
|
||||
"distinct",
|
||||
"powers"
|
||||
]
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
|
||||
83
ipython/EulerProblem030.ipynb
Executable file
83
ipython/EulerProblem030.ipynb
Executable file
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Euler Problem 30\n",
|
||||
"\n",
|
||||
"Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:\n",
|
||||
"\n",
|
||||
"$1634 = 1^4 + 6^4 + 3^4 + 4^4$\n",
|
||||
"\n",
|
||||
"$8208 = 8^4 + 2^4 + 0^4 + 8^4$\n",
|
||||
"\n",
|
||||
"$9474 = 9^4 + 4^4 + 7^4 + 4^4$\n",
|
||||
"\n",
|
||||
"As $1 = 1^4$ is not a sum it is not included.\n",
|
||||
"\n",
|
||||
"The sum of these numbers is $1634 + 8208 + 9474 = 19316$.\n",
|
||||
"\n",
|
||||
"Find the sum of all the numbers that can be written as the sum of fifth powers of their digits."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"This is an eays brute force. We look up the fifth powers."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"443839\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"fifth_power_lookup = {str(i): i**5 for i in range(0,10)}\n",
|
||||
"\n",
|
||||
"def is_number_sum_of_fiths_powers_of_digits(n):\n",
|
||||
" return n == sum([fifth_power_lookup[d] for d in str(n)])\n",
|
||||
"\n",
|
||||
"s = sum([i for i in range(1, 1000000) if is_number_sum_of_fiths_powers_of_digits(i) and not i is 1])\n",
|
||||
"print(s)\n",
|
||||
"assert(s == 443839)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"completion_date": "Fri, 25 Aug 2017, 12:13",
|
||||
"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.3"
|
||||
},
|
||||
"tags": [
|
||||
"digit",
|
||||
"powers",
|
||||
"brute force"
|
||||
]
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
65
ipython/EulerProblem031.ipynb
Executable file
65
ipython/EulerProblem031.ipynb
Executable file
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Euler Problem 31\n",
|
||||
"\n",
|
||||
"In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:\n",
|
||||
"\n",
|
||||
"1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).\n",
|
||||
"\n",
|
||||
"It is possible to make £2 in the following way:\n",
|
||||
"\n",
|
||||
"1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p\n",
|
||||
"\n",
|
||||
"How many different ways can £2 be made using any number of coins?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"I really have mental issues to this in a non recursive way."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"\n",
|
||||
" "
|
||||
]
|
||||
}
|
||||
],
|
||||
"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.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in New Issue
Block a user