Finished 35. Had epiphany when lying in bed. Misinterpeted circular to mean permutations.

main
Felix Martin 2018-02-13 10:17:37 +01:00
parent 1a890cf71b
commit 01daa27f86
3 changed files with 441 additions and 33 deletions

File diff suppressed because one or more lines are too long

View File

@ -22,19 +22,11 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"78498\n"
]
}
],
"outputs": [],
"source": [
"def get_primes_smaller(number):\n",
" primes = []\n",
@ -52,7 +44,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 2,
"metadata": {
"collapsed": false
},
@ -75,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 3,
"metadata": {
"collapsed": false
},
@ -98,18 +90,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"s = [p for p in ps if is_circular(p)]"
]
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 4,
"metadata": {
"collapsed": false
},
@ -118,34 +99,71 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, 97, 113, 131, 199, 311, 337, 373, 733, 919, 991]\n"
"False solution 22\n"
]
}
],
"source": [
"print(s)"
"s = len([p for p in ps if is_circular(p)])\n",
"print(\"False solution {}\".format(s))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We did not read the problem properly. Cycles are obviously not the same as permutations. If we change that we should get the solution in no time."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
"source": [
"def cyles(xs):\n",
" if len(xs) <= 1:\n",
" return xs\n",
" return [xs[i:] + xs[:i] for i in range(len(xs))]\n",
"\n",
"prime_set = set(ps)\n",
"\n",
"def is_circular(p):\n",
" cs = cyles(str(p))\n",
" for c in cs:\n",
" if not int(\"\".join(c)) in prime_set:\n",
" return False\n",
" return True"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"text/plain": [
"55"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s = len([p for p in ps if is_circular(p)])\n",
"s"
]
}
],
"metadata": {
"completion_date": "Tue, 13 Feb 2018, 09:14",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
@ -162,7 +180,11 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.4"
}
},
"tags": [
"circular",
"combinations"
]
},
"nbformat": 4,
"nbformat_minor": 0

View File

@ -520,6 +520,19 @@
</td>
</tr>
<tr>
<td>Problem 035</td>
<td>Tue, 13 Feb 2018, 09:14</td>
<td><a href="EulerProblem035.html">Problem 035</a></td>
<td>
<kbd>circular</kbd>
<kbd>combinations</kbd>
</td>
</tr>
<tr>
<td>Problem 067</td>
<td>Fri, 5 Sep 2014, 07:36</td>