Add files via upload
This commit is contained in:
1 parent
c64083f2d8
commit
f4a544269b
1 file changed
+10
-229
+10
-229
@@ -1233,7 +1233,7 @@
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'487 + 539 == 1026'"
|
||||
"'537 + 489 == 1026'"
|
||||
]
|
||||
},
|
||||
"execution_count": 33,
|
||||
@@ -1256,8 +1256,8 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"CPU times: user 51.8 s, sys: 263 ms, total: 52 s\n",
|
||||
"Wall time: 53.5 s\n"
|
||||
"CPU times: user 32.1 s, sys: 91.8 ms, total: 32.2 s\n",
|
||||
"Wall time: 32.3 s\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1337,13 +1337,13 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"lambda Y,M,O,E,U: Y and M and ((100*Y+10*O+U) == (10*M+E)**2)\n"
|
||||
"lambda M,Y,O,U,E: Y and M and ((100*Y+10*O+U) == (10*M+E)**2)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(<function __main__.<lambda>>, 'YMOEU')"
|
||||
"(<function __main__.<lambda>>, 'MYOUE')"
|
||||
]
|
||||
},
|
||||
"execution_count": 36,
|
||||
@@ -1366,13 +1366,13 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"lambda A,Y,L,M,E,N,P,R,U,B: B and N and P and ((100*N+10*U+M) + (100*B+10*E+R) == (1000*P+100*L+10*A+Y))\n"
|
||||
"lambda A,Y,P,M,U,E,B,L,R,N: P and N and B and ((100*N+10*U+M) + (100*B+10*E+R) == (1000*P+100*L+10*A+Y))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(<function __main__.<lambda>>, 'AYLMENPRUB')"
|
||||
"(<function __main__.<lambda>>, 'AYPMUEBLRN')"
|
||||
]
|
||||
},
|
||||
"execution_count": 37,
|
||||
@@ -1422,7 +1422,7 @@
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'487 + 539 = 1026'"
|
||||
"'537 + 489 = 1026'"
|
||||
]
|
||||
},
|
||||
"execution_count": 39,
|
||||
@@ -1445,8 +1445,8 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"CPU times: user 3.37 s, sys: 17.9 ms, total: 3.39 s\n",
|
||||
"Wall time: 3.45 s\n"
|
||||
"CPU times: user 1.87 s, sys: 8.03 ms, total: 1.88 s\n",
|
||||
"Wall time: 1.89 s\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1470,225 +1470,6 @@
|
||||
"source": [
|
||||
"We get the same answer, but 15 times faster."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 67,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]"
|
||||
]
|
||||
},
|
||||
"execution_count": 67,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from itertools import count, chain, islice\n",
|
||||
"\n",
|
||||
"def count_calls(f):\n",
|
||||
" def f1(*args):\n",
|
||||
" f1.count += 1\n",
|
||||
" return f(*args)\n",
|
||||
" f1.count = 0\n",
|
||||
" return f1\n",
|
||||
" \n",
|
||||
"@count_calls\n",
|
||||
"def sieve(numbers):\n",
|
||||
" p = next(numbers)\n",
|
||||
" yield p\n",
|
||||
" yield from sieve((x for x in numbers if x % p))\n",
|
||||
"\n",
|
||||
"primes = sieve(count(2))\n",
|
||||
"[next(primes) for _ in range(10)]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 68,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||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6SviWC6l4bDpK9W\nM91Lw2XSV2uZ7qXhM+mrdUz30uiY9NUqpntptEz6agXTvbQ2TPoaO9O9tHYG+WD0zyQ5neSbfWM7\nkny/+ZD0cx+Ufu6+7UmOJzma5NZRFa7Jd/YsbN0KmzfD7t2wdy9cccW4q5Km2yBJ/8+A9y8wvquq\nfrn5egwgyXrgLmA9cDuwJ8mKP8BX08t0L43Hkj39qvpakrcucNdCi/km4KGqegk4keQ4sAE4uLoy\nNS3s3UvjtZqe/keSPJvkwSSXN2PXAs/17XOyGZNM91ILrPTqnT3A71dVJfkD4AHgQ8t9kp07d57f\n7nQ6dDqdFZajNjPdSyvX7XbpdrtDe75U1dI79do7B6rqxovdl2QbUFV1f3PfY8COqrqgvZOkBjm2\nJtvcHGzZAhs3wq5dnqiVVisJVbXic6WDtndCXw8/yTV9930Q+FazvR+4O8mlSa4DrgeeXmlxmlxe\nmSO105LtnSSfBzrAP03yPWAHsDHJTcDLwAngwwBVdSTJw8AR4EVgq3F+9vSn+8OHXeylNhmovTOS\nA9vemTr27qXRW6v2jnRRXpkjTQbfe0erYrqXJotJXytmupcmj0lfy2a6lyaXSV/LYrqXJptJXwMx\n3UvTwaSvJZnupelh0teiTPfS9DHpa0Gme2k6mfT1KqZ7abqZ9HWe6V6afiZ9me6lGLine truncated
|
||||
"text/plain": [
|
||||
"<matplotlib.figure.Figure at 0x10d338ac8>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%matplotlib inline\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import time\n",
|
||||
"import gc\n",
|
||||
"\n",
|
||||
"def f(n):\n",
|
||||
" gc.collect()\n",
|
||||
" sieve.count = 0\n",
|
||||
" primes = sieve(count(2))\n",
|
||||
" for i in range(n):\n",
|
||||
" next(primes)\n",
|
||||
" return sieve.count\n",
|
||||
"\n",
|
||||
"X = list(range(20, 401, 20))\n",
|
||||
"plt.plot(X, [f(n) for n in X]);"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 70,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"sieve.count = 0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 75,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"# List of Jupyter (IPython) Notebooks by Peter Norvig\n",
|
||||
"|**Logic and Number Puzzles**||[Advent of Code 2016](https://github.com/norvig/pytudes/blob/master/Advent of Code.ipynb)<br>*Puzzle site with a coding puzze each day for Advent 2016*|\n",
|
||||
"|[Translating English Sentences into Propositional Logic Statements](https://github.com/norvig/pytudes/blob/master/PropositionalLogic.ipynb)<br>*Automatically converting informal English sentences into formal Propositional Logic.*|\n",
|
||||
"|[The Puzzle of the Misanthropic Neighbors](https://github.com/norvig/pytudes/blob/master/Mean Misanthrope Density.ipynb)<br>*How crowded will this neighborhood be, if nobody wants to live next door to anyone else?*|\n",
|
||||
"|[Countdown to 2016](https://github.com/norvig/pytudes/blob/master/Countdown.ipynb)<br>*Solving the equation 10 _ 9 _ 8 _ 7 _ 6 _ 5 _ 4 _ 3 _ 2 _ 1 = 2016. From an Alex Bellos puzzle.*|\n",
|
||||
"|[Sicherman Dice](https://github.com/norvig/pytudes/blob/master/Sicherman Dice.ipynb)<br>*Find a pair of dice that is like a regular pair of dice, only different.*|\n",
|
||||
"|[Beal's Conjecture Revisited<sup>2</sup>](https://github.com/norvig/pytudes/blob/master/Beal.ipynb)<br>*A search for counterexamples to Beal's Conjecture*|\n",
|
||||
"|[When is Cheryl's Birthday?](https://github.com/norvig/pytudes/blob/master/Cheryl.ipynb)<br>*Solving the \"Cheryl's Birthday\" logic puzzle.*|\n",
|
||||
"|[When Cheryl Met Eve: A Birthday Story](https://github.com/norvig/pytudes/blob/master/Cheryl-and-Eve.ipynb)<br>*Inventing new puzzles in the Style of \"Cheryl's Birthday.\" *|\n",
|
||||
"|[Sol Golomb's Rectangle Puzzle](https://github.com/norvig/pytudes/blob/master/Golomb-Puzzle.ipynb)<br>*A Puzzle involving placing rectangles of different sizes inside a square. Bonus: cryptarithmetic.*|\n",
|
||||
"|[WWW: Will Warriors Win?](https://github.com/norvig/pytudes/blob/master/WWW.ipynb)<br>*Golden State Warriors probability of winning the 2016 NBA title.*|\n",
|
||||
"|**Word Games**||[World's Longest Palindrome](https://github.com/norvig/pytudes/blob/master/pal3.ipynb)<br>*Searching for a long Panama-style palindrome, this time letter-by-letter.*|\n",
|
||||
"|[Refactoring a Crossword Game Program](https://github.com/norvig/pytudes/blob/master/Scrabble.ipynb)<br>*Refactoring the Scrabble / Word with Friends game from Udacity 212.*|\n",
|
||||
"|[xkcd 1313: Regex Golf](https://github.com/norvig/pytudes/blob/master/xkcd1313.ipynb)<br>*Find the smallest regular expression; inspired by Randall Monroe.*|\n",
|
||||
"|[xkcd 1313: Regex Golf (Part 2: Infinite Problems)](https://github.com/norvig/pytudes/blob/master/xkcd1313-part2.ipynb)<br>*Regex Golf: better, faster, funer. With Stefan Pochmann.*|\n",
|
||||
"|[Let's Code About Bike Locks](https://github.com/norvig/pytudes/blob/master/Fred Buns.ipynb)<br>*A tale of a bicycle combination lock that uses letters instead of digits. Inspired by Bike Snob NYC.*|\n",
|
||||
"|[Gesture Typing](https://github.com/norvig/pytudes/blob/master/Gesture Typing.ipynb)<br>*What word has the longest path on a gesture-typing smartphone keyboard? Inspired by Nicolas Schank and Shumin Zhai.*|\n",
|
||||
"|[How to Do Things with Words, or Statistical Natural Language Processing in Python](https://github.com/norvig/pytudes/blob/master/How to Do Things with Words.ipynb)<br>*Spelling Correction, Secret Codes, Word Segmentation, and more: grab your bag of words.*|\n",
|
||||
"|**Computer Science Algorithms, Concepts, and Problems**||[BASIC Interpreter](https://github.com/norvig/pytudes/blob/master/BASIC.ipynb)<br>*How to write an interpreter for the BASIC programming language.*|\n",
|
||||
"|[Conway's Game of Life](https://github.com/norvig/pytudes/blob/master/Life.ipynb)<br>*The cellular automata zero-player game.*|\n",
|
||||
"|[A Concrete Introduction to Probability](https://github.com/norvig/pytudes/blob/master/Probability.ipynb)<br>*Code and examples of the basic principles of Probability Theory.*|\n",
|
||||
"|[Probability, Paradox, and the Reasonable Person Principle](https://github.com/norvig/pytudes/blob/master/ProbabilityParadox.ipynb)<br>*Some classic paradoxes in Probability Theory, and how too think about disagreements.*|\n",
|
||||
"|[The Convex Hull Problem](https://github.com/norvig/pytudes/blob/master/Convex Hull.ipynb)<br>*A classic Computer Science Algorithm.*|\n",
|
||||
"|[The Traveling Salesperson Problem](https://github.com/norvig/pytudes/blob/master/TSP.ipynb)<br>*Another of the classics.*|\n",
|
||||
"|[Economics Simulation](https://github.com/norvig/pytudes/blob/master/Economics.ipynb)<br>*A simulation of a simple economic game.*|\n",
|
||||
"|[Project Euler Utilities](https://github.com/norvig/pytudes/blob/master/Project Euler Utils.ipynb)<br>*My utility functions for the Project Euler problems, including `Primes` and `Factors`.*|\n",
|
||||
"<p><hr><a href=\"http://norvig.com\">Peter Norvig</a>\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Generate the index of IPython notebooks\n",
|
||||
"\n",
|
||||
"def nb(name, title, description):\n",
|
||||
" base = 'https://github.com/norvig/pytudes/blob/master/'\n",
|
||||
" raw = 'https://raw.githubusercontent.com/norvig/pytudes/master/'\n",
|
||||
" return \"|[{}]({})<br>*{}*|\".format(title, base+name+'.ipynb', description)\n",
|
||||
"\n",
|
||||
"def section(name, *stuff):\n",
|
||||
" return \"|**{}**|\".format(name) + render(*stuff)\n",
|
||||
"\n",
|
||||
"def render(*stuff): return '\\n'.join(stuff)\n",
|
||||
" \n",
|
||||
"PAGE = render(\"# List of Jupyter (IPython) Notebooks by Peter Norvig\",\n",
|
||||
" section(\"Logic and Number Puzzles\", \n",
|
||||
" nb(\"Advent of Code\", \"Advent of Code 2016\",\n",
|
||||
" \"Puzzle site with a coding puzze each day for Advent 2016\"),\n",
|
||||
" nb(\"PropositionalLogic\", \"Translating English Sentences into Propositional Logic Statements\",\n",
|
||||
" \"Automatically converting informal English sentences into formal Propositional Logic.\"),\n",
|
||||
" nb(\"Mean Misanthrope Density\", \"The Puzzle of the Misanthropic Neighbors\",\n",
|
||||
" \"How crowded will this neighborhood be, if nobody wants to live next door to anyone else?\"),\n",
|
||||
" nb(\"Countdown\", \"Countdown to 2016\",\n",
|
||||
" \"Solving the equation 10 _ 9 _ 8 _ 7 _ 6 _ 5 _ 4 _ 3 _ 2 _ 1 = 2016. From an Alex Bellos puzzle.\"),\n",
|
||||
" nb(\"Sicherman Dice\", \"Sicherman Dice\",\n",
|
||||
" \"Find a pair of dice that is like a regular pair of dice, only different.\"),\n",
|
||||
" nb(\"Beal\", \"Beal's Conjecture Revisited<sup>2</sup>\", \n",
|
||||
" \"A search for counterexamples to Beal's Conjecture\"),\n",
|
||||
" nb(\"Cheryl\", \"When is Cheryl's Birthday?\", \n",
|
||||
" \"\"\"Solving the \"Cheryl's Birthday\" logic puzzle.\"\"\"),\n",
|
||||
" nb(\"Cheryl-and-Eve\", \"When Cheryl Met Eve: A Birthday Story\", \n",
|
||||
" \"\"\"Inventing new puzzles in the Style of \"Cheryl's Birthday.\" \"\"\"),\n",
|
||||
" nb(\"Golomb-Puzzle\", \"Sol Golomb's Rectangle Puzzle\", \n",
|
||||
" \"A Puzzle involving placing rectangles of different sizes inside a square. Bonus: cryptarithmetic.\"),\n",
|
||||
" nb(\"WWW\", \"WWW: Will Warriors Win?\",\n",
|
||||
" \"Golden State Warriors probability of winning the 2016 NBA title.\"),\n",
|
||||
" ),\n",
|
||||
" section(\"Word Games\",\n",
|
||||
" nb(\"pal3\", \"World's Longest Palindrome\",\n",
|
||||
" \"Searching for a long Panama-style palindrome, this time letter-by-letter.\"),\n",
|
||||
" nb(\"Scrabble\", \"Refactoring a Crossword Game Program\",\n",
|
||||
" \"Refactoring the Scrabble / Word with Friends game from Udacity 212.\"),\n",
|
||||
" nb(\"xkcd1313\", \"xkcd 1313: Regex Golf\", \n",
|
||||
" \"Find the smallest regular expression; inspired by Randall Monroe.\"),\n",
|
||||
" nb(\"xkcd1313-part2\", \"xkcd 1313: Regex Golf (Part 2: Infinite Problems)\", \n",
|
||||
" \"Regex Golf: better, faster, funer. With Stefan Pochmann.\"),\n",
|
||||
" nb(\"Fred Buns\", \"Let's Code About Bike Locks\",\n",
|
||||
" \"A tale of a bicycle combination lock that uses letters instead of digits. Inspired by Bike Snob NYC.\"),\n",
|
||||
" nb(\"Gesture Typing\", \"Gesture Typing\",\n",
|
||||
" \"What word has the longest path on a gesture-typing smartphone keyboard? Inspired by Nicolas Schank and Shumin Zhai.\"),\n",
|
||||
" nb(\"How to Do Things with Words\", \"How to Do Things with Words, or Statistical Natural Language Processing in Python\",\n",
|
||||
" \"Spelling Correction, Secret Codes, Word Segmentation, and more: grab your bag of words.\")\n",
|
||||
" ),\n",
|
||||
" section(\"Computer Science Algorithms, Concepts, and Problems\",\n",
|
||||
" nb(\"BASIC\", \"BASIC Interpreter\", \n",
|
||||
" \"How to write an interpreter for the BASIC programming language.\"),\n",
|
||||
" nb(\"Life\", \"Conway's Game of Life\",\n",
|
||||
" \"The cellular automata zero-player game.\"),\n",
|
||||
" nb(\"Probability\", \"A Concrete Introduction to Probability\",\n",
|
||||
" \"Code and examples of the basic principles of Probability Theory.\"),\n",
|
||||
" nb(\"ProbabilityParadox\", \"Probability, Paradox, and the Reasonable Person Principle\",\n",
|
||||
" \"Some classic paradoxes in Probability Theory, and how too think about disagreements.\"),\n",
|
||||
" nb(\"Convex Hull\", \"The Convex Hull Problem\", \"A classic Computer Science Algorithm.\"),\n",
|
||||
" nb(\"TSP\", \"The Traveling Salesperson Problem\", \"Another of the classics.\"),\n",
|
||||
" nb(\"Economics\", \"Economics Simulation\", \"A simulation of a simple economic game.\"),\n",
|
||||
" nb(\"Project Euler Utils\", \"Project Euler Utilities\", \n",
|
||||
" \"My utility functions for the Project Euler problems, including `Primes` and `Factors`.\")\n",
|
||||
" ),\n",
|
||||
" \"\"\"<p><hr><a href=\"http://norvig.com\">Peter Norvig</a>\"\"\")\n",
|
||||
"\n",
|
||||
"print(PAGE)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def maxpath(M):\n",
|
||||
" if not M: return 0\n",
|
||||
" R, C = len(mat), len(mat[0])\n",
|
||||
" totals = [[inf] * C for r in range(R)]\n",
|
||||
" for r in range(R):\n",
|
||||
" for c in range(C):\n",
|
||||
" totals[r][c] = M[r][c] + min(totals[r1][c1] for (r1, c1) in neighbors(r, c))\n",
|
||||
" return totals[r = 1][c - 1], totals\n",
|
||||
"\n",
|
||||
"def neighbors(r, c):\n",
|
||||
" if r"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
||||
Reference in new issue
Block a user