Compare commits

..

11 Commits

Author SHA1 Message Date
Peter Norvig
2e8234232d Update explanation of modular exponentiation 2026-03-29 19:44:23 -07:00
Peter Norvig
be1195dfa6 Fix formatting in TruncatablePrimes.ipynb 2026-03-29 18:50:31 -07:00
Peter Norvig
6712e8f626 Fix wording in TruncatablePrimes.ipynb 2026-03-29 18:50:08 -07:00
Peter Norvig
9ec6d0565e Add files via upload 2026-03-29 18:32:37 -07:00
Peter Norvig
5b9b2c2a11 Add files via upload 2026-03-25 17:16:09 -07:00
Peter Norvig
32dda84d1a Fix formatting issues in xkcd1313 notebook 2026-03-25 11:11:41 -07:00
Peter Norvig
1011a6c263 Remove unused code cells from xkcd1313 notebook 2026-03-25 11:10:19 -07:00
Peter Norvig
b499e06b97 Fix formatting of update message in xkcd1313 notebook 2026-03-25 11:08:28 -07:00
Peter Norvig
5d8afafae0 Fix formatting issue in Orderable Cards notebook 2026-03-24 14:37:41 -07:00
github-actions[bot]
7dd20e0759 docs: auto-update README.md via pytudes.py 2026-03-24 21:34:45 +00:00
Peter Norvig
345f95b1b1 Rename card hand description for clarity 2026-03-24 14:34:31 -07:00
8 changed files with 1321 additions and 1388 deletions

View File

@@ -142,7 +142,7 @@ For each notebook you can hover on the title to see a description, or click the
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/RiddlerLottery.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FRiddlerLottery.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FRiddlerLottery.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/RiddlerLottery.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/RiddlerLottery.ipynb) | 2019 | <a href="ipynb/RiddlerLottery.ipynb" title="Can you find what lottery number tickets these five friends picked?">Lottery</a> |
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/NightKing.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FNightKing.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FNightKing.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/NightKing.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/NightKing.ipynb) | 2019 | <a href="ipynb/NightKing.ipynb" title="A battle between the army of the dead and the army of the living">How Many Soldiers to Beat the Night King?</a> |
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Mean%20Misanthrope%20Density.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FMean%20Misanthrope%20Density.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FMean%20Misanthrope%20Density.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Mean%20Misanthrope%20Density.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Mean%20Misanthrope%20Density.ipynb) | 2017 | <a href="ipynb/Mean%20Misanthrope%20Density.ipynb" title="How crowded will this neighborhood be, if nobody wants to live next door to anyone else?">Misanthropic Neighbors</a> |
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Orderable%20Cards.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FOrderable%20Cards.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FOrderable%20Cards.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Orderable%20Cards.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Orderable%20Cards.ipynb) | 2018 | <a href="ipynb/Orderable%20Cards.ipynb" title="Can you get your hand of cards into a nice order with just one move?">Properly Ordered Card Hands</a> |
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Orderable%20Cards.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FOrderable%20Cards.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FOrderable%20Cards.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Orderable%20Cards.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Orderable%20Cards.ipynb) | 2018 | <a href="ipynb/Orderable%20Cards.ipynb" title="Can you get your hand of cards into a nice order with just one move?">Properly Organized Card Hands</a> |
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/RaceTrack.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FRaceTrack.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FRaceTrack.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/RaceTrack.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/RaceTrack.ipynb) | 2021 | <a href="ipynb/RaceTrack.ipynb" title="Race virtual cars around a circular track defined on a grid of points.">Race Track</a> |
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/SplitStates.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FSplitStates.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FSplitStates.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/SplitStates.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/SplitStates.ipynb) | 2021 | <a href="ipynb/SplitStates.ipynb" title="Split the US states into two near-halves by area.">Split the States</a> |
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/TourDe538.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FTourDe538.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FTourDe538.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/TourDe538.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/TourDe538.ipynb) | 2020 | <a href="ipynb/TourDe538.ipynb" title="Solve a puzzle involving the best pace for a bicycle race.">Tour de 538</a> |

View File

@@ -29,7 +29,7 @@
"|*N*|Concrete Hands|Abstract Hands|\n",
"|--|---|---|\n",
"|6|20,358,520|4,096|\n",
"13|635,013,559,600|67,108,864|\n",
"|13|635,013,559,600|67,108,864|\n",
"|*N*|(52 choose *N*) | *N*<sup>4</sup>|\n",
"\n",
"That's a big improvement! Now let's start designing a program to solve the problem:\n",

File diff suppressed because one or more lines are too long

View File

@@ -13,11 +13,11 @@
"\n",
"[![](https://community.wolfram.com//c/portal/getImageAttachment?filename=IMG_20181212_120939.jpg&userId=143131)](https://community.wolfram.com/groups/-/m/t/1569707)\n",
"\n",
"The 24-digit number printed on it is a prime, and as you sharpen the pencil and remove digits one at a time from the left, the resulting numbers are all primes:\n",
"The 24-digit number printed on this pencil is a prime, and as you sharpen the pencil and remove digits one at a time from the left, the resulting numbers are all primes:\n",
"\n",
" 357686312646216567629137 is prime\n",
" 57686312646216567629137 is prime\n",
" 7686312646216567629137 is prime|\n",
" 7686312646216567629137 is prime\n",
" ...\n",
" 137 is prime\n",
" 37 is prime\n",
@@ -1127,7 +1127,7 @@
"\n",
"# Note on Modular Exponentiation\n",
"\n",
"Just one more thing: none of this would work unless we can efficiently compute *a*<sup>(*n* - 1)</sup> (mod *n*). How does the `pow` builtin function do it? When *a* and *n* are 24-digit numbers, if we naively tried to compute `a ** (n - 1)`, we'd have two problems: we'd need nearly a billion petabytes to store the result, and we'd need centuries to compute it. The way around these problems is to use [modular exponentiation](https://en.wikipedia.org/wiki/Modular_exponentiation) where we apply the modulus to each intermediate result, and cut the exponent in half each iteration, so we need only do *O*(log *n*) multiplications, not *O*(*n*). That's a big difference: 10<sup>24</sup> is a trillion trillion, and log<sub>2</sub>(10<sup>24</sup>) is only 80. \n",
"Just one more thing: none of this would work unless we can efficiently compute *a*<sup>(*n* - 1)</sup> (mod *n*). How does the `pow` builtin function do it? When *a* and *n* are 24-digit numbers, if we naively tried to compute `a ** (n - 1)` and then apply (mod *n*), we'd have two problems: we'd need nearly a billion petabytes to store the result, and we'd need centuries to compute it. The way around these problems is to use [modular exponentiation](https://en.wikipedia.org/wiki/Modular_exponentiation) where we apply the modulus to each intermediate result, and cut the exponent in half each iteration, so we need only do *O*(log *n*) multiplications, not *O*(*n*). That's a big difference: 10<sup>24</sup> is a trillion trillion, and log<sub>2</sub>(10<sup>24</sup>) is only 80. \n",
"\n",
"There are two key ides that make this work:\n",
"1) *b*<sup>2*e*</sup> = (*b* × *b*)<sup>*e*</sup>\n",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -98,7 +98,7 @@ notebooks = {
('Lottery', 2019, 'RiddlerLottery.ipynb', 'Can you find what lottery number tickets these five friends picked?'),
('How Many Soldiers to Beat the Night King?', 2019, 'NightKing.ipynb', 'A battle between the army of the dead and the army of the living'),
('Misanthropic Neighbors', 2017, 'Mean%20Misanthrope%20Density.ipynb', 'How crowded will this neighborhood be, if nobody wants to live next door to anyone else?'),
('Properly Ordered Card Hands', 2018, 'Orderable%20Cards.ipynb', 'Can you get your hand of cards into a nice order with just one move?'),
('Properly Organized Card Hands', 2018, 'Orderable%20Cards.ipynb', 'Can you get your hand of cards into a nice order with just one move?'),
('Race Track', 2021, 'RaceTrack.ipynb', 'Race virtual cars around a circular track defined on a grid of points.'),
('Split the States', 2021, 'SplitStates.ipynb', 'Split the US states into two near-halves by area.'),
('Tour de 538', 2020, 'TourDe538.ipynb', 'Solve a puzzle involving the best pace for a bicycle race.'),