Compare commits
23 Commits
6e45084acb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05edde6c33 | ||
|
|
ceb79dd67f | ||
|
|
76e35e2cd3 | ||
|
|
a2f6772b66 | ||
|
|
8fbf7b4a19 | ||
|
|
8a5a7fd4f8 | ||
|
|
af3fb185ef | ||
|
|
3db6443929 | ||
|
|
c9c763f97f | ||
|
|
9ec85ae31e | ||
|
|
59007a6145 | ||
|
|
84616c6a9b | ||
|
|
2d8286014f | ||
|
|
10e2880c9b | ||
|
|
dba5328b8a | ||
|
|
57fc06e78c | ||
|
|
cbe3c7a9b3 | ||
|
|
7b24391b7b | ||
|
|
d67caa2820 | ||
|
|
7ac2359e88 | ||
|
|
9e14d0c5ac | ||
|
|
759bc14257 | ||
|
|
8e4b98eba4 |
3
.github/workflows/on-file-change.yml
vendored
3
.github/workflows/on-file-change.yml
vendored
@@ -5,6 +5,9 @@ on:
|
|||||||
paths:
|
paths:
|
||||||
- 'py/pytudes.py'
|
- 'py/pytudes.py'
|
||||||
|
|
||||||
|
env:
|
||||||
|
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-update:
|
build-and-update:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
242
README.md
242
README.md
@@ -15,155 +15,149 @@ To continue the musical analogy, some people think of programming like [Spotify]
|
|||||||
|
|
||||||
# Index of Jupyter (IPython) Notebooks
|
# Index of Jupyter (IPython) Notebooks
|
||||||
|
|
||||||
For each notebook you can hover on the title to see a description, or click the title to view on github, or click one of the letters in the left column to launch the notebook on
|
For each notebook you can hover on the title to see a description, or click the title to view on github, or click one of the letters in the left column to open the notebook on
|
||||||
[**C**olab](https://colab.research.google.com),
|
[**co**lab](https://colab.research.google.com) or
|
||||||
[**D**eepnote](https://deepnote.com),
|
[**nb**viewer](https://nbviewer.jupyter.org/).
|
||||||
[**M**ybinder](https://mybinder.org),
|
|
||||||
[**S**agemaker](https://studiolab.sagemaker.aws/), or
|
|
||||||
[**N**BViewer](https://nbviewer.jupyter.org/).
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|Run|Year|New|
|
|Open|Year|New|
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/clvr.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2Fclvr.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2Fclvr.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/clvr.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/clvr.ipynb) | 2026 | <a href="ipynb/clvr.ipynb" title="Guess famous phrases from letter shapes. Beginner level.">Did you solve it? R y clvr ngh t rd ths sntnc?</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/lispy.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/lispy.ipynb) | 2026 | <a href="ipynb/lispy.ipynb" title="Tutorial on interpreters.">(How to Write a (Lisp) Interpreter (in Python))</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Euler3.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FEuler3.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FEuler3.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Euler3.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Euler3.ipynb) | 2026 | <a href="ipynb/Euler3.ipynb" title="Find the largest prime factor of a number">Project Euler #3: Largest prime factor</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/RationalPi.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/RationalPi.ipynb) | 2026 | <a href="ipynb/RationalPi.ipynb" title="Using continued fractions to find fractions (like 22/7) that are close to pi.">Approximating Pi with a Fraction</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/TruncatablePrimes.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FTruncatablePrimes.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FTruncatablePrimes.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/TruncatablePrimes.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/TruncatablePrimes.ipynb) | 2026 | <a href="ipynb/TruncatablePrimes.ipynb" title="Prime numbers where you can remove digits and still get primes.">Truncatable Primes</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/clvr.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/clvr.ipynb) | 2026 | <a href="ipynb/clvr.ipynb" title="Guess famous phrases from letter shapes. Beginner level.">Did you solve it? R y clvr ngh t rd ths sntnc?</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2025.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdvent-2025.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdvent-2025.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2025.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Advent-2025.ipynb) | 2025 | <a href="ipynb/Advent-2025.ipynb" title="Puzzle site with a coding puzzle for 12 days of Christmas, December 2025">Advent of Code 2025</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Euler3.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Euler3.ipynb) | 2026 | <a href="ipynb/Euler3.ipynb" title="Find the largest prime factor of a number">Project Euler #3: Largest prime factor</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2025-AI.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdvent-2025-AI.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdvent-2025-AI.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2025-AI.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Advent-2025-AI.ipynb) | 2025 | <a href="ipynb/Advent-2025-AI.ipynb" title="Using large language coding models to solve AoC puzzles">Advent of Code 2025: AI LLM Edition</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/TruncatablePrimes.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/TruncatablePrimes.ipynb) | 2026 | <a href="ipynb/TruncatablePrimes.ipynb" title="Prime numbers where you can remove digits and still get primes.">Truncatable Primes</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2024.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdvent-2024.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdvent-2024.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2024.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Advent-2024.ipynb) | 2024 | <a href="ipynb/Advent-2024.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2024">Advent of Code 2024</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2025.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2025.ipynb) | 2025 | <a href="ipynb/Advent-2025.ipynb" title="Puzzle site with a coding puzzle for 12 days of Christmas, December 2025">Advent of Code 2025</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Paint.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FPaint.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FPaint.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Paint.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Paint.ipynb) | 2024 | <a href="ipynb/Paint.ipynb" title="What is the average cluster size of a random grid of colored squares?">Counting Cluster Sizes in Paint by Numbers</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2025-AI.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2025-AI.ipynb) | 2025 | <a href="ipynb/Advent-2025-AI.ipynb" title="Using large language coding models to solve AoC puzzles">Advent of Code 2025: AI LLM Edition</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/CherylMind.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FCherylMind.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FCherylMind.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/CherylMind.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/CherylMind.ipynb) | 2024 | <a href="ipynb/CherylMind.ipynb" title="Do LLMs have enough theory of mind to solve the Cheryl's Birthday puzzle?">LLMs, Theory of Mind, and Cheryl's Birthday</a> |
|
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/NumberBracelets.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FNumberBracelets.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FNumberBracelets.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/NumberBracelets.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/NumberBracelets.ipynb) | 2024 | <a href="ipynb/NumberBracelets.ipynb" title="A game involving numbered beads on a circular bracelet.">Number Bracelets Game</a> |
|
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Overtime.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FOvertime.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FOvertime.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Overtime.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Overtime.ipynb) | 2024 | <a href="ipynb/Overtime.ipynb" title="In American Football, which team has the advantage in overtime?">Overtime in American Football</a> |
|
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Stubborn.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FStubborn.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FStubborn.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Stubborn.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Stubborn.ipynb) | 2024 | <a href="ipynb/Stubborn.ipynb" title="Any number ending in 5 has a square that also ends in 5. What other endings are like this?">Stubborn number endings</a> |
|
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Triplets.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FTriplets.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FTriplets.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Triplets.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Triplets.ipynb) | 2024 | <a href="ipynb/Triplets.ipynb" title="LLMs do better at producing a program to solve this puzzle than they do at solving it directly">The Languages of English, Math, and Programming</a> |
|
|
||||||
|
|
||||||
|
|
||||||
|Run|Year|Programming Examples|
|
|Open|Year|Programming Examples|
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/AlphaCode.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAlphaCode.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAlphaCode.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/AlphaCode.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/AlphaCode.ipynb) | 2022 | <a href="ipynb/AlphaCode.ipynb" title="Analysis of AlphaCode's automated solution to a coding problem">AlphaCode Automated Programming</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/AlphaCode.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/AlphaCode.ipynb) | 2022 | <a href="ipynb/AlphaCode.ipynb" title="Analysis of AlphaCode's automated solution to a coding problem">AlphaCode Automated Programming</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Babylonian%20digits.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FBabylonian%20digits.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FBabylonian%20digits.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Babylonian%20digits.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Babylonian%20digits.ipynb) | 2022 | <a href="ipynb/Babylonian%20digits.ipynb" title="Translating between Babylonian and traditional number systems.">The Babylonian Number System</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/RationalPi.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/RationalPi.ipynb) | 2026 | <a href="ipynb/RationalPi.ipynb" title="Using continued fractions to find fractions (like 22/7) that are close to pi.">Approximating Pi with a Fraction</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Beal.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FBeal.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FBeal.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Beal.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Beal.ipynb) | 2018 | <a href="ipynb/Beal.ipynb" title="A search for counterexamples to Beal's Conjecture">Beal's Conjecture Revisited</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Babylonian%20digits.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Babylonian%20digits.ipynb) | 2022 | <a href="ipynb/Babylonian%20digits.ipynb" title="Translating between Babylonian and traditional number systems.">The Babylonian Number System</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Bike-Stats.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FBike-Stats.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FBike-Stats.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Bike-Stats.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Bike-Stats.ipynb) | 2020 | <a href="ipynb/Bike-Stats.ipynb" title="Visualizing statistics about bike routes">Bicycling Statistics</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Beal.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Beal.ipynb) | 2018 | <a href="ipynb/Beal.ipynb" title="A search for counterexamples to Beal's Conjecture">Beal's Conjecture Revisited</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Cant-Stop.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FCant-Stop.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FCant-Stop.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Cant-Stop.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Cant-Stop.ipynb) | 2018 | <a href="ipynb/Cant-Stop.ipynb" title="Optimal play in a dice board game">Can't Stop</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Bike-Stats.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Bike-Stats.ipynb) | 2020 | <a href="ipynb/Bike-Stats.ipynb" title="Visualizing statistics about bike routes">Bicycling Statistics</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Sierpinski.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FSierpinski.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FSierpinski.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Sierpinski.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Sierpinski.ipynb) | 2019 | <a href="ipynb/Sierpinski.ipynb" title="A surprising appearance of the Sierpinski triangle in a random walk">Chaos with Triangles</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Cant-Stop.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Cant-Stop.ipynb) | 2018 | <a href="ipynb/Cant-Stop.ipynb" title="Optimal play in a dice board game">Can't Stop</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Life.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FLife.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FLife.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Life.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Life.ipynb) | 2017 | <a href="ipynb/Life.ipynb" title="The cellular automata zero-player game">Conway's Game of Life</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Sierpinski.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Sierpinski.ipynb) | 2019 | <a href="ipynb/Sierpinski.ipynb" title="A surprising appearance of the Sierpinski triangle in a random walk">Chaos with Triangles</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Maze.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FMaze.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FMaze.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Maze.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Maze.ipynb) | 2020 | <a href="ipynb/Maze.ipynb" title="Make a maze by generating a random tree superimposed on a grid and solve it">Generating and Solving Mazes</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Life.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Life.ipynb) | 2017 | <a href="ipynb/Life.ipynb" title="The cellular automata zero-player game">Conway's Game of Life</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Triplets.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FTriplets.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FTriplets.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Triplets.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Triplets.ipynb) | 2024 | <a href="ipynb/Triplets.ipynb" title="LLMs do better at producing a program to solve this puzzle than they do at solving it directly">The Languages of English, Math, and Programming</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Maze.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Maze.ipynb) | 2020 | <a href="ipynb/Maze.ipynb" title="Make a maze by generating a random tree superimposed on a grid and solve it">Generating and Solving Mazes</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Konane.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FKonane.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FKonane.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Konane.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Konane.ipynb) | 2021 | <a href="ipynb/Konane.ipynb" title="Solving the game of Konane (Hawaiian checkers).">Mel's Konane Board</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Triplets.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Triplets.ipynb) | 2024 | <a href="ipynb/Triplets.ipynb" title="LLMs do better at producing a program to solve this puzzle than they do at solving it directly">The Languages of English, Math, and Programming</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/PhotoFocalLengths.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FPhotoFocalLengths.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FPhotoFocalLengths.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/PhotoFocalLengths.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/PhotoFocalLengths.ipynb) | 2020 | <a href="ipynb/PhotoFocalLengths.ipynb" title="Generate charts of what focal lengths were used on a photo trip">Photo Focal Lengths</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Konane.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Konane.ipynb) | 2021 | <a href="ipynb/Konane.ipynb" title="Solving the game of Konane (Hawaiian checkers).">Mel's Konane Board</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Pickleball.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FPickleball.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FPickleball.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Pickleball.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Pickleball.ipynb) | 2018 | <a href="ipynb/Pickleball.ipynb" title="Scheduling a doubles tournament fairly and efficiently">Pickleball Tournament</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/PhotoFocalLengths.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/PhotoFocalLengths.ipynb) | 2020 | <a href="ipynb/PhotoFocalLengths.ipynb" title="Generate charts of what focal lengths were used on a photo trip">Photo Focal Lengths</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Project%20Euler%20Utils.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FProject%20Euler%20Utils.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FProject%20Euler%20Utils.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Project%20Euler%20Utils.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Project%20Euler%20Utils.ipynb) | 2017 | <a href="ipynb/Project%20Euler%20Utils.ipynb" title="My utility functions for the Project Euler problems, including `Primes` and `Factors`">Project Euler Utilities</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Pickleball.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Pickleball.ipynb) | 2018 | <a href="ipynb/Pickleball.ipynb" title="Scheduling a doubles tournament fairly and efficiently">Pickleball Tournament</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Menu.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FMenu.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FMenu.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Menu.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Menu.ipynb) | 2022 | <a href="ipynb/Menu.ipynb" title="Efficiently Selecting Names from a Menu, by typing characters and arrows">Selecting Names from a Menu</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Project%20Euler%20Utils.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Project%20Euler%20Utils.ipynb) | 2017 | <a href="ipynb/Project%20Euler%20Utils.ipynb" title="My utility functions for the Project Euler problems, including `Primes` and `Factors`">Project Euler Utilities</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Electoral%20Votes.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FElectoral%20Votes.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FElectoral%20Votes.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Electoral%20Votes.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Electoral%20Votes.ipynb) | 2020 | <a href="ipynb/Electoral%20Votes.ipynb" title="How many electoral votes would Trump get if he wins the state where he has positive net approval?">Tracking Polls: Electoral Votes</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Menu.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Menu.ipynb) | 2022 | <a href="ipynb/Menu.ipynb" title="Efficiently Selecting Names from a Menu, by typing characters and arrows">Selecting Names from a Menu</a> |
|
||||||
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Electoral%20Votes.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Electoral%20Votes.ipynb) | 2020 | <a href="ipynb/Electoral%20Votes.ipynb" title="How many electoral votes would Trump get if he wins the state where he has positive net approval?">Tracking Polls: Electoral Votes</a> |
|
||||||
|
|
||||||
|
|
||||||
|Run|Year|Advent of Code|
|
|Open|Year|Advent of Code|
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2025-AI.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdvent-2025-AI.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdvent-2025-AI.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2025-AI.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Advent-2025-AI.ipynb) | 2025 | <a href="ipynb/Advent-2025-AI.ipynb" title="Using large language coding models to solve AoC puzzles">Advent of Code 2025: AI LLM Edition</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2025-AI.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2025-AI.ipynb) | 2025 | <a href="ipynb/Advent-2025-AI.ipynb" title="Using large language coding models to solve AoC puzzles">Advent of Code 2025: AI LLM Edition</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2025.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdvent-2025.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdvent-2025.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2025.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Advent-2025.ipynb) | 2025 | <a href="ipynb/Advent-2025.ipynb" title="Puzzle site with a coding puzzle for 12 days of Christmas, December 2025">Advent of Code 2025</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2025.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2025.ipynb) | 2025 | <a href="ipynb/Advent-2025.ipynb" title="Puzzle site with a coding puzzle for 12 days of Christmas, December 2025">Advent of Code 2025</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2024.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdvent-2024.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdvent-2024.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2024.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Advent-2024.ipynb) | 2024 | <a href="ipynb/Advent-2024.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2024">Advent of Code 2024</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2024.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2024.ipynb) | 2024 | <a href="ipynb/Advent-2024.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2024">Advent of Code 2024</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2023.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdvent-2023.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdvent-2023.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2023.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Advent-2023.ipynb) | 2023 | <a href="ipynb/Advent-2023.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2023">Advent of Code 2023</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2023.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2023.ipynb) | 2023 | <a href="ipynb/Advent-2023.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2023">Advent of Code 2023</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2022.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdvent-2022.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdvent-2022.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2022.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Advent-2022.ipynb) | 2022 | <a href="ipynb/Advent-2022.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2022">Advent of Code 2022</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2022.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2022.ipynb) | 2022 | <a href="ipynb/Advent-2022.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2022">Advent of Code 2022</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2021.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdvent-2021.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdvent-2021.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2021.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Advent-2021.ipynb) | 2021 | <a href="ipynb/Advent-2021.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2021">Advent of Code 2021</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2021.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2021.ipynb) | 2021 | <a href="ipynb/Advent-2021.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2021">Advent of Code 2021</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2020.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdvent-2020.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdvent-2020.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2020.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Advent-2020.ipynb) | 2020 | <a href="ipynb/Advent-2020.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2020">Advent of Code 2020</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2020.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2020.ipynb) | 2020 | <a href="ipynb/Advent-2020.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2020">Advent of Code 2020</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2018.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdvent-2018.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdvent-2018.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2018.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Advent-2018.ipynb) | 2018 | <a href="ipynb/Advent-2018.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2018">Advent of Code 2018</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2018.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2018.ipynb) | 2018 | <a href="ipynb/Advent-2018.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2018">Advent of Code 2018</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2017.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdvent-2017.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdvent-2017.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2017.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Advent-2017.ipynb) | 2017 | <a href="ipynb/Advent-2017.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2017">Advent of Code 2017</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2017.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2017.ipynb) | 2017 | <a href="ipynb/Advent-2017.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2017">Advent of Code 2017</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2016.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdvent-2016.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdvent-2016.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2016.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Advent-2016.ipynb) | 2016 | <a href="ipynb/Advent-2016.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2016">Advent of Code 2016</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Advent-2016.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Advent-2016.ipynb) | 2016 | <a href="ipynb/Advent-2016.ipynb" title="Puzzle site with a coding puzzle each day of Advent, December 2016">Advent of Code 2016</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/AdventUtils.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAdventUtils.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAdventUtils.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/AdventUtils.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/AdventUtils.ipynb) | 2022 | <a href="ipynb/AdventUtils.ipynb" title="Utility functions for Advent of Code puzzles">Advent of Code Utilities</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/AdventUtils.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/AdventUtils.ipynb) | 2022 | <a href="ipynb/AdventUtils.ipynb" title="Utility functions for Advent of Code puzzles">Advent of Code Utilities</a> |
|
||||||
|
|
||||||
|
|
||||||
|Run|Year|Probability and Uncertainty|
|
|Open|Year|Probability and Uncertainty|
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Goldberg.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FGoldberg.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FGoldberg.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Goldberg.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Goldberg.ipynb) | 2019 | <a href="ipynb/Goldberg.ipynb" title="A re-implementation in Python 3 of Yoav Goldberg's unreasonably effective character-level n-gram language model.">Effectiveness of Language Models</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Goldberg.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Goldberg.ipynb) | 2019 | <a href="ipynb/Goldberg.ipynb" title="A re-implementation in Python 3 of Yoav Goldberg's unreasonably effective character-level n-gram language model.">Effectiveness of Language Models</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Probability.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FProbability.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FProbability.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Probability.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Probability.ipynb) | 2018 | <a href="ipynb/Probability.ipynb" title="Code and examples of the basic principles of Probability Theory">A Concrete Introduction to Probability</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Probability.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Probability.ipynb) | 2018 | <a href="ipynb/Probability.ipynb" title="Code and examples of the basic principles of Probability Theory">A Concrete Introduction to Probability</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/ProbabilityParadox.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FProbabilityParadox.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FProbabilityParadox.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/ProbabilityParadox.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/ProbabilityParadox.ipynb) | 2016 | <a href="ipynb/ProbabilityParadox.ipynb" title="Some classic paradoxes in Probability Theory, and how to think about disagreements">Probability, Paradox, and the Reasonable Person Principle</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/ProbabilityParadox.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/ProbabilityParadox.ipynb) | 2016 | <a href="ipynb/ProbabilityParadox.ipynb" title="Some classic paradoxes in Probability Theory, and how to think about disagreements">Probability, Paradox, and the Reasonable Person Principle</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/ProbabilitySimulation.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FProbabilitySimulation.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FProbabilitySimulation.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/ProbabilitySimulation.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/ProbabilitySimulation.ipynb) | 2020 | <a href="ipynb/ProbabilitySimulation.ipynb" title="When the sample space is too complex, simulations can estimate probabilities">Estimating Probabilities with Simulations</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/ProbabilitySimulation.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/ProbabilitySimulation.ipynb) | 2020 | <a href="ipynb/ProbabilitySimulation.ipynb" title="When the sample space is too complex, simulations can estimate probabilities">Estimating Probabilities with Simulations</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Diamonds.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FDiamonds.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FDiamonds.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Diamonds.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Diamonds.ipynb) | 2023 | <a href="ipynb/Diamonds.ipynb" title="Finding an optimal strategy for buying bags with unknown numbers of diamonds.">The Diamond Game: A Probability Puzzle</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Diamonds.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Diamonds.ipynb) | 2023 | <a href="ipynb/Diamonds.ipynb" title="Finding an optimal strategy for buying bags with unknown numbers of diamonds.">The Diamond Game: A Probability Puzzle</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Coin%20Flip.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FCoin%20Flip.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FCoin%20Flip.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Coin%20Flip.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Coin%20Flip.ipynb) | 2019 | <a href="ipynb/Coin%20Flip.ipynb" title="How to beat the Devil at his own game">The Devil and the Coin Flip Game</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Coin%20Flip.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Coin%20Flip.ipynb) | 2019 | <a href="ipynb/Coin%20Flip.ipynb" title="How to beat the Devil at his own game">The Devil and the Coin Flip Game</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Dice%20Baseball.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FDice%20Baseball.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FDice%20Baseball.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Dice%20Baseball.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Dice%20Baseball.ipynb) | 2020 | <a href="ipynb/Dice%20Baseball.ipynb" title="Simulating baseball games">Dice Baseball</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Dice%20Baseball.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Dice%20Baseball.ipynb) | 2020 | <a href="ipynb/Dice%20Baseball.ipynb" title="Simulating baseball games">Dice Baseball</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Economics.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FEconomics.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FEconomics.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Economics.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Economics.ipynb) | 2018 | <a href="ipynb/Economics.ipynb" title="A simulation of a simple economic game">Economics Simulation</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Economics.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Economics.ipynb) | 2018 | <a href="ipynb/Economics.ipynb" title="A simulation of a simple economic game">Economics Simulation</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Overtime.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FOvertime.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FOvertime.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Overtime.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Overtime.ipynb) | 2024 | <a href="ipynb/Overtime.ipynb" title="In American Football, which team has the advantage in overtime?">Overtime in American Football</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Overtime.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Overtime.ipynb) | 2024 | <a href="ipynb/Overtime.ipynb" title="In American Football, which team has the advantage in overtime?">Overtime in American Football</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/poker.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2Fpoker.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2Fpoker.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/poker.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/poker.ipynb) | 2012 | <a href="ipynb/poker.ipynb" title="How do we decide which poker hand wins? Several variants of poker are considered">Poker Hand Ranking</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/poker.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/poker.ipynb) | 2012 | <a href="ipynb/poker.ipynb" title="How do we decide which poker hand wins? Several variants of poker are considered">Poker Hand Ranking</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/risk.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2Frisk.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2Frisk.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/risk.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/risk.ipynb) | 2020 | <a href="ipynb/risk.ipynb" title="Determining who is likely to win an interminably long game of Risk">The Unfinished Game .... of Risk</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/risk.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/risk.ipynb) | 2020 | <a href="ipynb/risk.ipynb" title="Determining who is likely to win an interminably long game of Risk">The Unfinished Game .... of Risk</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/WWW.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FWWW.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FWWW.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/WWW.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/WWW.ipynb) | 2019 | <a href="ipynb/WWW.ipynb" title="Computing the probability of winning the NBA title, for my home town Warriors, or any other team">WWW: Who Will Win (NBA Title)?</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/WWW.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/WWW.ipynb) | 2019 | <a href="ipynb/WWW.ipynb" title="Computing the probability of winning the NBA title, for my home town Warriors, or any other team">WWW: Who Will Win (NBA Title)?</a> |
|
||||||
|
|
||||||
|
|
||||||
|Run|Year|Logic and Number/Counting Puzzles|
|
|Open|Year|Logic and Number/Counting Puzzles|
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Paint.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FPaint.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FPaint.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Paint.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Paint.ipynb) | 2024 | <a href="ipynb/Paint.ipynb" title="What is the average cluster size of a random grid of colored squares?">Counting Cluster Sizes in Paint by Numbers</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Paint.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Paint.ipynb) | 2024 | <a href="ipynb/Paint.ipynb" title="What is the average cluster size of a random grid of colored squares?">Counting Cluster Sizes in Paint by Numbers</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Cryptarithmetic.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FCryptarithmetic.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FCryptarithmetic.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Cryptarithmetic.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Cryptarithmetic.ipynb) | 2014 | <a href="ipynb/Cryptarithmetic.ipynb" title="Substitute digits for letters and make NUM + BER = PLAY">Cryptarithmetic</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Cryptarithmetic.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Cryptarithmetic.ipynb) | 2014 | <a href="ipynb/Cryptarithmetic.ipynb" title="Substitute digits for letters and make NUM + BER = PLAY">Cryptarithmetic</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Euler's%20Conjecture.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FEuler's%20Conjecture.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FEuler's%20Conjecture.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Euler's%20Conjecture.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Euler's%20Conjecture.ipynb) | 2018 | <a href="ipynb/Euler's%20Conjecture.ipynb" title="Solving a 200-year-old puzzle by finding integers that satisfy a<sup>5</sup> + b<sup>5</sup> + c<sup>5</sup> + d<sup>5</sup> = e<sup>5</sup>">Euler's Sum of Powers Conjecture</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Euler's%20Conjecture.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Euler's%20Conjecture.ipynb) | 2018 | <a href="ipynb/Euler's%20Conjecture.ipynb" title="Solving a 200-year-old puzzle by finding integers that satisfy a<sup>5</sup> + b<sup>5</sup> + c<sup>5</sup> + d<sup>5</sup> = e<sup>5</sup>">Euler's Sum of Powers Conjecture</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Countdown.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FCountdown.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FCountdown.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Countdown.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Countdown.ipynb) | 2020 | <a href="ipynb/Countdown.ipynb" title="Solving the equation 10 _ 9 _ 8 _ 7 _ 6 _ 5 _ 4 _ 3 _ 2 _ 1 = 2016. Originally from an Alex Bellos puzzle">Four 4s, Five 5s, and Countdowns</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Countdown.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Countdown.ipynb) | 2020 | <a href="ipynb/Countdown.ipynb" title="Solving the equation 10 _ 9 _ 8 _ 7 _ 6 _ 5 _ 4 _ 3 _ 2 _ 1 = 2016. Originally from an Alex Bellos puzzle">Four 4s, Five 5s, and Countdowns</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/How%20To%20Count%20Things.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FHow%20To%20Count%20Things.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FHow%20To%20Count%20Things.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/How%20To%20Count%20Things.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/How%20To%20Count%20Things.ipynb) | 2020 | <a href="ipynb/How%20To%20Count%20Things.ipynb" title="Combinatorial math: how to count how many things there are, when there are a lot of them">How to Count Things</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/How%20To%20Count%20Things.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/How%20To%20Count%20Things.ipynb) | 2020 | <a href="ipynb/How%20To%20Count%20Things.ipynb" title="Combinatorial math: how to count how many things there are, when there are a lot of them">How to Count Things</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/KenKen.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FKenKen.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FKenKen.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/KenKen.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/KenKen.ipynb) | 2021 | <a href="ipynb/KenKen.ipynb" title="A Sudoku-like puzzle, but with arithmetic.">KenKen (Sudoku-like Puzzle)</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/KenKen.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/KenKen.ipynb) | 2021 | <a href="ipynb/KenKen.ipynb" title="A Sudoku-like puzzle, but with arithmetic.">KenKen (Sudoku-like Puzzle)</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/NumberBracelets.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FNumberBracelets.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FNumberBracelets.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/NumberBracelets.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/NumberBracelets.ipynb) | 2024 | <a href="ipynb/NumberBracelets.ipynb" title="A game involving numbered beads on a circular bracelet.">Number Bracelets Game</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/NumberBracelets.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/NumberBracelets.ipynb) | 2024 | <a href="ipynb/NumberBracelets.ipynb" title="A game involving numbered beads on a circular bracelet.">Number Bracelets Game</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Euler3.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FEuler3.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FEuler3.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Euler3.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Euler3.ipynb) | 2026 | <a href="ipynb/Euler3.ipynb" title="Find the largest prime factor of a number">Project Euler #3: Largest prime factor</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Euler3.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Euler3.ipynb) | 2026 | <a href="ipynb/Euler3.ipynb" title="Find the largest prime factor of a number">Project Euler #3: Largest prime factor</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Socks.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FSocks.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FSocks.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Socks.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Socks.ipynb) | 2019 | <a href="ipynb/Socks.ipynb" title="What is the probability that you will be able to pair up socks as you randomly pull them out of the dryer?">Pairing Socks</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Socks.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Socks.ipynb) | 2019 | <a href="ipynb/Socks.ipynb" title="What is the probability that you will be able to pair up socks as you randomly pull them out of the dryer?">Pairing Socks</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Sicherman%20Dice.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FSicherman%20Dice.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FSicherman%20Dice.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Sicherman%20Dice.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Sicherman%20Dice.ipynb) | 2018 | <a href="ipynb/Sicherman%20Dice.ipynb" title="Find a pair of dice that is like a regular pair of dice, only different">Sicherman Dice</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Sicherman%20Dice.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Sicherman%20Dice.ipynb) | 2018 | <a href="ipynb/Sicherman%20Dice.ipynb" title="Find a pair of dice that is like a regular pair of dice, only different">Sicherman Dice</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Golomb-Puzzle.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FGolomb-Puzzle.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FGolomb-Puzzle.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Golomb-Puzzle.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Golomb-Puzzle.ipynb) | 2014 | <a href="ipynb/Golomb-Puzzle.ipynb" title="A Puzzle involving placing rectangles of different sizes inside a square">Sol Golomb's Rectangle Puzzle</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Golomb-Puzzle.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Golomb-Puzzle.ipynb) | 2014 | <a href="ipynb/Golomb-Puzzle.ipynb" title="A Puzzle involving placing rectangles of different sizes inside a square">Sol Golomb's Rectangle Puzzle</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Stubborn.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FStubborn.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FStubborn.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Stubborn.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Stubborn.ipynb) | 2024 | <a href="ipynb/Stubborn.ipynb" title="Any number ending in 5 has a square that also ends in 5. What other endings are like this?">Stubborn number endings</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Stubborn.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Stubborn.ipynb) | 2024 | <a href="ipynb/Stubborn.ipynb" title="Any number ending in 5 has a square that also ends in 5. What other endings are like this?">Stubborn number endings</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/StarBattle.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FStarBattle.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FStarBattle.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/StarBattle.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/StarBattle.ipynb) | 2021 | <a href="ipynb/StarBattle.ipynb" title="Fill-in-the-grid puzzle similar to Sudoku">Star Battle (Sudoku-like Puzzle)</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/StarBattle.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/StarBattle.ipynb) | 2021 | <a href="ipynb/StarBattle.ipynb" title="Fill-in-the-grid puzzle similar to Sudoku">Star Battle (Sudoku-like Puzzle)</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Sudoku.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FSudoku.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FSudoku.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Sudoku.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Sudoku.ipynb) | 2006 | <a href="ipynb/Sudoku.ipynb" title="Classic fill-in-the-grid puzzle">Sudoku</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Sudoku.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Sudoku.ipynb) | 2006 | <a href="ipynb/Sudoku.ipynb" title="Classic fill-in-the-grid puzzle">Sudoku</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/SudokuJava.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FSudokuJava.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FSudokuJava.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/SudokuJava.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/SudokuJava.ipynb) | 2021 | <a href="ipynb/SudokuJava.ipynb" title="A version of the Sudoku solver using parallel threads and other optimizations">Sudoku: 200,000 puzzles/second in Java</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/SudokuJava.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/SudokuJava.ipynb) | 2021 | <a href="ipynb/SudokuJava.ipynb" title="A version of the Sudoku solver using parallel threads and other optimizations">Sudoku: 200,000 puzzles/second in Java</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/SquareSum.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FSquareSum.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FSquareSum.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/SquareSum.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/SquareSum.ipynb) | 2020 | <a href="ipynb/SquareSum.ipynb" title="Place the numbers from 1 to n in a chain (or a circle) such that adjacent pairs sum to a perfect square">Square Sum Puzzle</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/SquareSum.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/SquareSum.ipynb) | 2020 | <a href="ipynb/SquareSum.ipynb" title="Place the numbers from 1 to n in a chain (or a circle) such that adjacent pairs sum to a perfect square">Square Sum Puzzle</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Cheryl.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FCheryl.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FCheryl.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Cheryl.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Cheryl.ipynb) | 2020 | <a href="ipynb/Cheryl.ipynb" title="Solving the *Cheryl's Birthday* logic puzzle">When is Cheryl's Birthday?</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Cheryl.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Cheryl.ipynb) | 2020 | <a href="ipynb/Cheryl.ipynb" title="Solving the *Cheryl's Birthday* logic puzzle">When is Cheryl's Birthday?</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Cheryl-and-Eve.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FCheryl-and-Eve.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FCheryl-and-Eve.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Cheryl-and-Eve.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Cheryl-and-Eve.ipynb) | 2015 | <a href="ipynb/Cheryl-and-Eve.ipynb" title="Inventing new puzzles in the Style of Cheryl's Birthday">When Cheryl Met Eve: A Birthday Story</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Cheryl-and-Eve.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Cheryl-and-Eve.ipynb) | 2015 | <a href="ipynb/Cheryl-and-Eve.ipynb" title="Inventing new puzzles in the Style of Cheryl's Birthday">When Cheryl Met Eve: A Birthday Story</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/CherylMind.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FCherylMind.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FCherylMind.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/CherylMind.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/CherylMind.ipynb) | 2024 | <a href="ipynb/CherylMind.ipynb" title="Do LLMs have enough theory of mind to solve the Cheryl's Birthday puzzle?">LLMs, Theory of Mind, and Cheryl's Birthday</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/CherylMind.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/CherylMind.ipynb) | 2024 | <a href="ipynb/CherylMind.ipynb" title="Do LLMs have enough theory of mind to solve the Cheryl's Birthday puzzle?">LLMs, Theory of Mind, and Cheryl's Birthday</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/xkcd1313.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2Fxkcd1313.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2Fxkcd1313.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/xkcd1313.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/xkcd1313.ipynb) | 2015 | <a href="ipynb/xkcd1313.ipynb" title="Find the smallest regular expression; inspired by Randall Munroe">xkcd 1313: Regex Golf</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/xkcd1313.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/xkcd1313.ipynb) | 2015 | <a href="ipynb/xkcd1313.ipynb" title="Find the smallest regular expression; inspired by Randall Munroe">xkcd 1313: Regex Golf</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/xkcd1313-part2.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2Fxkcd1313-part2.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2Fxkcd1313-part2.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/xkcd1313-part2.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/xkcd1313-part2.ipynb) | 2015 | <a href="ipynb/xkcd1313-part2.ipynb" title="Regex Golf: better, faster, funner (with Stefan Pochmann)">xkcd 1313: Regex Golf (Part 2: Infinite Problems)</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/xkcd1313-part2.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/xkcd1313-part2.ipynb) | 2015 | <a href="ipynb/xkcd1313-part2.ipynb" title="Regex Golf: better, faster, funner (with Stefan Pochmann)">xkcd 1313: Regex Golf (Part 2: Infinite Problems)</a> |
|
||||||
|
|
||||||
|
|
||||||
|Run|Year|Word Puzzles|
|
|Open|Year|Word Puzzles|
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Boggle.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FBoggle.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FBoggle.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Boggle.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Boggle.ipynb) | 2020 | <a href="ipynb/Boggle.ipynb" title="Find all the words on a Boggle board; then find a board with a lot of words">Boggle / Inverse Boggle</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Boggle.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Boggle.ipynb) | 2020 | <a href="ipynb/Boggle.ipynb" title="Find all the words on a Boggle board; then find a board with a lot of words">Boggle / Inverse Boggle</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/ElementSpelling.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FElementSpelling.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FElementSpelling.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/ElementSpelling.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/ElementSpelling.ipynb) | 2020 | <a href="ipynb/ElementSpelling.ipynb" title="Spelling words using the chemical element symbols, like CoIn">Chemical Element Spelling</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/ElementSpelling.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/ElementSpelling.ipynb) | 2020 | <a href="ipynb/ElementSpelling.ipynb" title="Spelling words using the chemical element symbols, like CoIn">Chemical Element Spelling</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/clvr.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2Fclvr.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2Fclvr.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/clvr.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/clvr.ipynb) | 2026 | <a href="ipynb/clvr.ipynb" title="Guess famous phrases from letter shapes. Beginner level.">Did you solve it? R y clvr ngh t rd ths sntnc?</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/clvr.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/clvr.ipynb) | 2026 | <a href="ipynb/clvr.ipynb" title="Guess famous phrases from letter shapes. Beginner level.">Did you solve it? R y clvr ngh t rd ths sntnc?</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/equilength-numbers.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2Fequilength-numbers.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2Fequilength-numbers.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/equilength-numbers.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/equilength-numbers.ipynb) | 2020 | <a href="ipynb/equilength-numbers.ipynb" title="What number names have the same letter count as the number they name (such as FOUR)?">Equilength Numbers: FOUR = 4</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/equilength-numbers.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/equilength-numbers.ipynb) | 2020 | <a href="ipynb/equilength-numbers.ipynb" title="What number names have the same letter count as the number they name (such as FOUR)?">Equilength Numbers: FOUR = 4</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Gesture%20Typing.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FGesture%20Typing.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FGesture%20Typing.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Gesture%20Typing.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Gesture%20Typing.ipynb) | 2017 | <a href="ipynb/Gesture%20Typing.ipynb" title="What word has the longest path on a gesture-typing smartphone keyboard?">Gesture Typing</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Gesture%20Typing.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Gesture%20Typing.ipynb) | 2017 | <a href="ipynb/Gesture%20Typing.ipynb" title="What word has the longest path on a gesture-typing smartphone keyboard?">Gesture Typing</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Ghost.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FGhost.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FGhost.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Ghost.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Ghost.ipynb) | 2017 | <a href="ipynb/Ghost.ipynb" title="The word game Ghost (add letters, try to avoid making a word)">Ghost: A Word game</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Ghost.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Ghost.ipynb) | 2017 | <a href="ipynb/Ghost.ipynb" title="The word game Ghost (add letters, try to avoid making a word)">Ghost: A Word game</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/How%20to%20Do%20Things%20with%20Words.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FHow%20to%20Do%20Things%20with%20Words.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FHow%20to%20Do%20Things%20with%20Words.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/How%20to%20Do%20Things%20with%20Words.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/How%20to%20Do%20Things%20with%20Words.ipynb) | 2018 | <a href="ipynb/How%20to%20Do%20Things%20with%20Words.ipynb" title="Spelling Correction, Secret Codes, Word Segmentation, and more">How to Do Things with Words: NLP in Python</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/How%20to%20Do%20Things%20with%20Words.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/How%20to%20Do%20Things%20with%20Words.ipynb) | 2018 | <a href="ipynb/How%20to%20Do%20Things%20with%20Words.ipynb" title="Spelling Correction, Secret Codes, Word Segmentation, and more">How to Do Things with Words: NLP in Python</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Fred%20Buns.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FFred%20Buns.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FFred%20Buns.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Fred%20Buns.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Fred%20Buns.ipynb) | 2015 | <a href="ipynb/Fred%20Buns.ipynb" title="A tale of a bicycle combination lock that uses letters instead of digits. Inspired by Bike Snob NYC">Let's Code About Bike Locks</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Fred%20Buns.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Fred%20Buns.ipynb) | 2015 | <a href="ipynb/Fred%20Buns.ipynb" title="A tale of a bicycle combination lock that uses letters instead of digits. Inspired by Bike Snob NYC">Let's Code About Bike Locks</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/OneLetterOff.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FOneLetterOff.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FOneLetterOff.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/OneLetterOff.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/OneLetterOff.ipynb) | 2023 | <a href="ipynb/OneLetterOff.ipynb" title="Word game; use of a large language model to generate clues.">One Letter Off</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/OneLetterOff.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/OneLetterOff.ipynb) | 2023 | <a href="ipynb/OneLetterOff.ipynb" title="Word game; use of a large language model to generate clues.">One Letter Off</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Scrabble.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FScrabble.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FScrabble.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Scrabble.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Scrabble.ipynb) | 2017 | <a href="ipynb/Scrabble.ipynb" title="Refactoring the Scrabble / Word with Friends game from Udacity 212">Scrabble: Refactoring a Crossword Game Program</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Scrabble.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Scrabble.ipynb) | 2017 | <a href="ipynb/Scrabble.ipynb" title="Refactoring the Scrabble / Word with Friends game from Udacity 212">Scrabble: Refactoring a Crossword Game Program</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/SpellingBee.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FSpellingBee.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FSpellingBee.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/SpellingBee.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/SpellingBee.ipynb) | 2020 | <a href="ipynb/SpellingBee.ipynb" title="Find the highest-scoring board for the NY Times Spelling Bee puzzle">Spelling Bee</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/SpellingBee.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/SpellingBee.ipynb) | 2020 | <a href="ipynb/SpellingBee.ipynb" title="Find the highest-scoring board for the NY Times Spelling Bee puzzle">Spelling Bee</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/PropositionalLogic.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FPropositionalLogic.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FPropositionalLogic.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/PropositionalLogic.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/PropositionalLogic.ipynb) | 2017 | <a href="ipynb/PropositionalLogic.ipynb" title="Automatically convert informal English sentences into formal Propositional Logic">Translating English into Propositional Logic</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/PropositionalLogic.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/PropositionalLogic.ipynb) | 2017 | <a href="ipynb/PropositionalLogic.ipynb" title="Automatically convert informal English sentences into formal Propositional Logic">Translating English into Propositional Logic</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Jotto.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FJotto.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FJotto.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Jotto.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Jotto.ipynb) | 2020 | <a href="ipynb/Jotto.ipynb" title="The word guessing games Wordle, Evil Wordle, Antiwordle, and Jotto">Wordle, Evil Wordle, Antiwordle, and Jotto</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Jotto.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Jotto.ipynb) | 2020 | <a href="ipynb/Jotto.ipynb" title="The word guessing games Wordle, Evil Wordle, Antiwordle, and Jotto">Wordle, Evil Wordle, Antiwordle, and Jotto</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Wordle.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FWordle.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FWordle.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Wordle.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Wordle.ipynb) | 2022 | <a href="ipynb/Wordle.ipynb" title="A simple human-usable strategy to always win at Wordle. And an analysis of 2-guess wins">Winning Wordle</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Wordle.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Wordle.ipynb) | 2022 | <a href="ipynb/Wordle.ipynb" title="A simple human-usable strategy to always win at Wordle. And an analysis of 2-guess wins">Winning Wordle</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/pal3.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2Fpal3.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2Fpal3.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/pal3.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/pal3.ipynb) | 2017 | <a href="ipynb/pal3.ipynb" title="Searching for a long Panama-style palindrome, this time letter-by-letter">World's Longest Palindrome</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/pal3.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/pal3.ipynb) | 2017 | <a href="ipynb/pal3.ipynb" title="Searching for a long Panama-style palindrome, this time letter-by-letter">World's Longest Palindrome</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Portmantout.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FPortmantout.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FPortmantout.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Portmantout.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Portmantout.ipynb) | 2020 | <a href="ipynb/Portmantout.ipynb" title="Find a word that squishes together a bunch of words">World's Shortest Portmantout Word</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Portmantout.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Portmantout.ipynb) | 2020 | <a href="ipynb/Portmantout.ipynb" title="Find a word that squishes together a bunch of words">World's Shortest Portmantout Word</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/xkcd-Name-Dominoes.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2Fxkcd-Name-Dominoes.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2Fxkcd-Name-Dominoes.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/xkcd-Name-Dominoes.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/xkcd-Name-Dominoes.ipynb) | 2018 | <a href="ipynb/xkcd-Name-Dominoes.ipynb" title="Lay out dominoes legally; the dominoes have people names, not numbers">xkcd 1970: Name Dominoes</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/xkcd-Name-Dominoes.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/xkcd-Name-Dominoes.ipynb) | 2018 | <a href="ipynb/xkcd-Name-Dominoes.ipynb" title="Lay out dominoes legally; the dominoes have people names, not numbers">xkcd 1970: Name Dominoes</a> |
|
||||||
|
|
||||||
|
|
||||||
|Run|Year|The Riddler (from 538)|
|
|Open|Year|The Riddler (from 538)|
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Anigrams.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FAnigrams.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FAnigrams.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Anigrams.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Anigrams.ipynb) | 2022 | <a href="ipynb/Anigrams.ipynb" title="Finding the longest chain of anagrams that each add one letter">Anigrams: Word Chains</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Anigrams.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Anigrams.ipynb) | 2022 | <a href="ipynb/Anigrams.ipynb" title="Finding the longest chain of anagrams that each add one letter">Anigrams: Word Chains</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Riddler%20Battle%20Royale.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FRiddler%20Battle%20Royale.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FRiddler%20Battle%20Royale.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Riddler%20Battle%20Royale.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Riddler%20Battle%20Royale.ipynb) | 2017 | <a href="ipynb/Riddler%20Battle%20Royale.ipynb" title="A puzzle involving allocating your troops and going up against an opponent">Battle Royale</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Riddler%20Battle%20Royale.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Riddler%20Battle%20Royale.ipynb) | 2017 | <a href="ipynb/Riddler%20Battle%20Royale.ipynb" title="A puzzle involving allocating your troops and going up against an opponent">Battle Royale</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/ClimbingWall.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FClimbingWall.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FClimbingWall.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/ClimbingWall.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/ClimbingWall.ipynb) | 2021 | <a href="ipynb/ClimbingWall.ipynb" title="How many holds have to be placed to make a path in each climbing event">Climbing Wall</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/ClimbingWall.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/ClimbingWall.ipynb) | 2021 | <a href="ipynb/ClimbingWall.ipynb" title="How many holds have to be placed to make a path in each climbing event">Climbing Wall</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/CrossProduct.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FCrossProduct.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FCrossProduct.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/CrossProduct.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/CrossProduct.ipynb) | 2021 | <a href="ipynb/CrossProduct.ipynb" title="A puzzle where digits fill a table, subject to constraints on their products">CrossProduct</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/CrossProduct.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/CrossProduct.ipynb) | 2021 | <a href="ipynb/CrossProduct.ipynb" title="A puzzle where digits fill a table, subject to constraints on their products">CrossProduct</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/flipping.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2Fflipping.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2Fflipping.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/flipping.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/flipping.ipynb) | 2020 | <a href="ipynb/flipping.ipynb" title="Can you go through a deck of cards, guessing higher or lower correctly for each card?">Flipping Cards; A Guessing Game</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/flipping.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/flipping.ipynb) | 2020 | <a href="ipynb/flipping.ipynb" title="Can you go through a deck of cards, guessing higher or lower correctly for each card?">Flipping Cards; A Guessing Game</a> |
|
||||||
| [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> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/RiddlerLottery.ipynb) [nb](https://nbviewer.jupyter.org/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> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/NightKing.ipynb) [nb](https://nbviewer.jupyter.org/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> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Mean%20Misanthrope%20Density.ipynb) [nb](https://nbviewer.jupyter.org/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 Organized Card Hands</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Orderable%20Cards.ipynb) [nb](https://nbviewer.jupyter.org/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> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/RaceTrack.ipynb) [nb](https://nbviewer.jupyter.org/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> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/SplitStates.ipynb) [nb](https://nbviewer.jupyter.org/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> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/TourDe538.ipynb) [nb](https://nbviewer.jupyter.org/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> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/TwelveBalls.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FTwelveBalls.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FTwelveBalls.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/TwelveBalls.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/TwelveBalls.ipynb) | 2020 | <a href="ipynb/TwelveBalls.ipynb" title="A puzzle where you are given some billiard balls and a balance scale, and asked to find the one ball that is heavier or lighter, in a limited number of weighings">Weighing Twelve Balls</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/TwelveBalls.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/TwelveBalls.ipynb) | 2020 | <a href="ipynb/TwelveBalls.ipynb" title="A puzzle where you are given some billiard balls and a balance scale, and asked to find the one ball that is heavier or lighter, in a limited number of weighings">Weighing Twelve Balls</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/war.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2Fwar.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2Fwar.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/war.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/war.ipynb) | 2020 | <a href="ipynb/war.ipynb" title="How likely is it to win a game of war in 26 turns?">War. What is it Good For?</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/war.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/war.ipynb) | 2020 | <a href="ipynb/war.ipynb" title="How likely is it to win a game of war in 26 turns?">War. What is it Good For?</a> |
|
||||||
|
|
||||||
|
|
||||||
|Run|Year|Computer Science Algorithms and Concepts|
|
|Open|Year|Computer Science Algorithms and Concepts|
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/BASIC.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FBASIC.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FBASIC.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/BASIC.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/BASIC.ipynb) | 2017 | <a href="ipynb/BASIC.ipynb" title="How to write an interpreter for the BASIC programming language">BASIC Interpreter</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/BASIC.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/BASIC.ipynb) | 2017 | <a href="ipynb/BASIC.ipynb" title="How to write an interpreter for the BASIC programming language">BASIC Interpreter</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Convex%20Hull.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FConvex%20Hull.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FConvex%20Hull.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Convex%20Hull.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Convex%20Hull.ipynb) | 2017 | <a href="ipynb/Convex%20Hull.ipynb" title="A classic Computer Science Algorithm">Convex Hull Problem</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Convex%20Hull.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Convex%20Hull.ipynb) | 2017 | <a href="ipynb/Convex%20Hull.ipynb" title="A classic Computer Science Algorithm">Convex Hull Problem</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/DocstringFixpoint.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FDocstringFixpoint.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FDocstringFixpoint.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/DocstringFixpoint.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/DocstringFixpoint.ipynb) | 2023 | <a href="ipynb/DocstringFixpoint.ipynb" title="An approach to writing code and docstrings that go together.">Docstring Fixpoint Theory</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/lispy.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/lispy.ipynb) | 2026 | <a href="ipynb/lispy.ipynb" title="Tutorial on interpreters.">(How to Write a (Lisp) Interpreter (in Python))</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/StableMatching.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FStableMatching.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FStableMatching.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/StableMatching.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/StableMatching.ipynb) | 2020 | <a href="ipynb/StableMatching.ipynb" title="What is the best way to pair up two groups with each other, obeying preferences?">Stable Matching Problem</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/DocstringFixpoint.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/DocstringFixpoint.ipynb) | 2023 | <a href="ipynb/DocstringFixpoint.ipynb" title="An approach to writing code and docstrings that go together.">Docstring Fixpoint Theory</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Differentiation.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FDifferentiation.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FDifferentiation.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Differentiation.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Differentiation.ipynb) | 2017 | <a href="ipynb/Differentiation.ipynb" title="A computer algebra system, including symbolic differentiation">Symbolic Algebra, Simplification, and Differentiation</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/StableMatching.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/StableMatching.ipynb) | 2020 | <a href="ipynb/StableMatching.ipynb" title="What is the best way to pair up two groups with each other, obeying preferences?">Stable Matching Problem</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Snobol.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FSnobol.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FSnobol.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Snobol.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/Snobol.ipynb) | 2017 | <a href="ipynb/Snobol.ipynb" title="As a student, did you ever get a bad grade on a programming assignment?">Snobol: Bad Grade, Good Experience</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Differentiation.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Differentiation.ipynb) | 2017 | <a href="ipynb/Differentiation.ipynb" title="A computer algebra system, including symbolic differentiation">Symbolic Algebra, Simplification, and Differentiation</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/TSP.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FTSP.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FTSP.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/TSP.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/TSP.ipynb) | 2018 | <a href="ipynb/TSP.ipynb" title="Another of the classics">Traveling Salesperson Problem</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/Snobol.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/Snobol.ipynb) | 2017 | <a href="ipynb/Snobol.ipynb" title="As a student, did you ever get a bad grade on a programming assignment?">Snobol: Bad Grade, Good Experience</a> |
|
||||||
| [C](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/TruncatablePrimes.ipynb) [D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2FTruncatablePrimes.ipynb) [M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2FTruncatablePrimes.ipynb) [N](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/TruncatablePrimes.ipynb) [S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes/blob/main/ipynb/TruncatablePrimes.ipynb) | 2026 | <a href="ipynb/TruncatablePrimes.ipynb" title="Prime numbers where you can remove digits and still get primes.">Truncatable Primes</a> |
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/TSP.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/TSP.ipynb) | 2018 | <a href="ipynb/TSP.ipynb" title="Another of the classics">Traveling Salesperson Problem</a> |
|
||||||
|
| [co](https://colab.research.google.com/github/norvig/pytudes/blob/main/ipynb/TruncatablePrimes.ipynb) [nb](https://nbviewer.jupyter.org/github/norvig/pytudes/blob/main/ipynb/TruncatablePrimes.ipynb) | 2026 | <a href="ipynb/TruncatablePrimes.ipynb" title="Prime numbers where you can remove digits and still get primes.">Truncatable Primes</a> |
|
||||||
|
|
||||||
# Index of Python Files
|
# Index of Python Files
|
||||||
|
|
||||||
|
|||||||
@@ -15,17 +15,17 @@
|
|||||||
" The prime factors of 13195 are 5, 7, 13 and 29.\n",
|
" The prime factors of 13195 are 5, 7, 13 and 29.\n",
|
||||||
" What is the largest prime factor of the number 600851475143?\n",
|
" What is the largest prime factor of the number 600851475143?\n",
|
||||||
"\n",
|
"\n",
|
||||||
"I'll describe here how I think about this problem. There are two things to get right: the general plan of how to attack this problem, and the details of how to say it in Python.\n",
|
"I'll describe here how I think about this problem, at alevel suitable for a novice programmer. There are two things to get right: the general plan of how to attack this problem, and the details of how to say it in Python.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"## The General Plan\n",
|
"## The General Plan\n",
|
||||||
"\n",
|
"\n",
|
||||||
"I would like to be able to find the largest prime factor of *any* integer, not just 600851475143; I want `largest_prime_factor(n)`. Here's how I think about it:\n",
|
"I would like to be able to find the largest prime factor of *any* integer, not just 600851475143; I want `largest_prime_factor(n)`. Here's how I think about it:\n",
|
||||||
"\n",
|
"\n",
|
||||||
"- I don't know how to immediately find the largest prime factor of *n*. (How would I know which numbers are prime?)\n",
|
"- I don't know how to immediately find the *largest* prime factor of *n*. \n",
|
||||||
"- I do know how to find the *smallest* prime factor: just go through the integers from 2 to *n*, in order. The first integer that evenly divides *n* must be the smallest prime factor. It is a factor because it evenly divides, it is smallest because we didn't find a smaller one first, and it is prime because if it were a composite number (like 4 or 9), then we would have found one of its factors (like 2 or 3) first.\n",
|
"- I do know how to find the *smallest* prime factor: just go through the integers from 2 to *n*, in order. The first integer that evenly divides *n* must be the smallest prime factor. It is a factor because it evenly divides, it is smallest because we didn't find a smaller one first, and it is prime because if it were a composite number (like 4 or 9), then we would have found one of its factors (like 2 or 3) first.\n",
|
||||||
"- Once I have the smallest prime factor ***p*** then I know: **the largest prime factor of *n* is the maximum of *p* and the largest prime factor of *n*/*p*.**\n",
|
"- Once I have the smallest prime factor ***p*** then I know: **the largest prime factor of *n* is the maximum of *p* and the largest prime factor of *n*/*p*.**\n",
|
||||||
"- If *n* is prime, then the largest prime factor is *n*.\n",
|
"- If *n* is prime, then the largest prime factor is *n*.\n",
|
||||||
"- If *n* is 1, then [by convention](https://oeis.org/wiki/Greatest_prime_factor_of_n) we say the greatest prime factor is 1, even though 1 is usually not considered a prime.\n"
|
"- If *n* is 1, then [by convention](https://oeis.org/wiki/Greatest_prime_factor_of_n) we say the largest prime factor is 1, even though 1 is usually not considered a prime."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
" \"\"\"The largest prime that evenly divides n.\n",
|
" \"\"\"The largest prime that evenly divides n.\n",
|
||||||
" Find the smallest prime p that evenly divides n, \n",
|
" Find the smallest prime p that evenly divides n, \n",
|
||||||
" and return the maximum of p and the largest prime factor of n/p.\n",
|
" and return the maximum of p and the largest prime factor of n/p.\n",
|
||||||
" For prime n and for 1, return n.\"\"\"\n",
|
" If n is prime or if n = 1, this will return n.\"\"\"\n",
|
||||||
" for p in range(2, n):\n",
|
" for p in range(2, n):\n",
|
||||||
" if n % p == 0: # n is composite\n",
|
" if n % p == 0: # n is composite\n",
|
||||||
" return max(p, largest_prime_factor(n // p))\n",
|
" return max(p, largest_prime_factor(n // p))\n",
|
||||||
@@ -105,29 +105,36 @@
|
|||||||
"id": "8bf8dd51-8e06-4572-85fa-fe42875e0305",
|
"id": "8bf8dd51-8e06-4572-85fa-fe42875e0305",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Example Factor Tree\n",
|
"We can represent the execution of the program as a series of equations, one per line. Using `F` as an abbreviation for `largest_prime_factor`, here is hjow we find the largest prime factor of 360:\n",
|
||||||
"\n",
|
"\n",
|
||||||
"[Here](https://www.cuemath.com/numbers/factor-tree/) is the \"factor tree\" of *n* = 36:\n",
|
" F(360) = max(2, F(180))\n",
|
||||||
"\n",
|
" F(180) = max(2, F(90))\n",
|
||||||
"<img src=\"factor36.png\" width=300>\n",
|
" F(90) = max(2, F(45))\n",
|
||||||
"\n",
|
" F(45) = max(3, F(15))\n",
|
||||||
"\n",
|
" F(15) = max(3, F(5))\n",
|
||||||
"We could also represent this as a series of equations, one per line:\n",
|
" F(5) = 5\n",
|
||||||
"\n",
|
" F(36) = max(2, max(2, max(2, 3, 3, 5))) = 5"
|
||||||
" 36 = 2 × 18\n",
|
]
|
||||||
" 18 = 2 × 9\n",
|
},
|
||||||
" 9 = 3 × 3\n",
|
{
|
||||||
" 3 = 3\n",
|
"cell_type": "code",
|
||||||
" 36 = 2 × 2 × 3 × 3\n",
|
"execution_count": 3,
|
||||||
"\n",
|
"id": "a4aaf952-bf6a-4dec-a950-5c573e1fbef0",
|
||||||
"\n",
|
"metadata": {},
|
||||||
"Or as equations for how `largest_prime_factor(36)` is broken down, with `lpf` as an abbreviation for `largest_prime_factor`:\n",
|
"outputs": [
|
||||||
"\n",
|
{
|
||||||
" lpf(36) = max(2, lpf(18))\n",
|
"data": {
|
||||||
" lpf(18) = max(2, lpf(9))\n",
|
"text/plain": [
|
||||||
" lpf(9) = max(3, lpf(3))\n",
|
"360"
|
||||||
" lpf(3) = 3\n",
|
]
|
||||||
" lpf(36) = max(2, max(2, max(3, 3))) = 3"
|
},
|
||||||
|
"execution_count": 3,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"2 * 2 * 2 * 3 * 3 * 5"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -142,33 +149,38 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 4,
|
||||||
"id": "9bedb1c9-4138-4250-90e6-77b10ba01586",
|
"id": "9bedb1c9-4138-4250-90e6-77b10ba01586",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"'all tests pass'"
|
"[11, 'out of', 11, 'tests pass']"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 3,
|
"execution_count": 4,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"def tests():\n",
|
"def tests():\n",
|
||||||
" assert largest_prime_factor(1) == 1 # by convention, 1\n",
|
" \"\"\"Test largest_prime_factor.\"\"\"\n",
|
||||||
" assert largest_prime_factor(2) == 2 # even prime\n",
|
" cases = {1: 1, # by convention, 1\n",
|
||||||
" assert largest_prime_factor(3) == 3 # odd prime\n",
|
" 2: 2, # even prime\n",
|
||||||
" assert largest_prime_factor(6) == 3 # composite\n",
|
" 3: 3, # odd prime\n",
|
||||||
" assert largest_prime_factor(8) == 2 # power of 2\n",
|
" 6: 3, # composite\n",
|
||||||
" assert largest_prime_factor(36) == 3 # example from the diagram\n",
|
" 32: 2, # power of 2\n",
|
||||||
" assert largest_prime_factor(49) == 7 # square of a prime\n",
|
" 49: 7, # square of a prime\n",
|
||||||
" assert largest_prime_factor(97) == 97 # bigger prime\n",
|
" 97: 97, # bigger prime\n",
|
||||||
" assert largest_prime_factor(600851475143) == 6857 # really big number\n",
|
" 99991: 99991, # even bigger prime\n",
|
||||||
" return 'all tests pass'\n",
|
" 97**9: 97, # even bigger power of a prime\n",
|
||||||
|
" 360: 5, # test case for equations above\n",
|
||||||
|
" 600851475143: 6857 # Project Euler #3\n",
|
||||||
|
" }\n",
|
||||||
|
" correct = sum(largest_prime_factor(n) == cases[n] for n in cases)\n",
|
||||||
|
" return [correct, 'out of', len(cases), 'tests pass']\n",
|
||||||
"\n",
|
"\n",
|
||||||
"tests()"
|
"tests()"
|
||||||
]
|
]
|
||||||
@@ -185,7 +197,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 5,
|
||||||
"id": "0e4a1dc6-5969-49fd-9d65-11d9801cbea2",
|
"id": "0e4a1dc6-5969-49fd-9d65-11d9801cbea2",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@@ -193,8 +205,8 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"CPU times: user 249 μs, sys: 20 μs, total: 269 μs\n",
|
"CPU times: user 181 μs, sys: 0 ns, total: 181 μs\n",
|
||||||
"Wall time: 296 μs\n"
|
"Wall time: 183 μs\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -203,7 +215,7 @@
|
|||||||
"6857"
|
"6857"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 4,
|
"execution_count": 5,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@@ -217,12 +229,12 @@
|
|||||||
"id": "c8ead8e9-199f-47c6-ad76-360b1ebdaa02",
|
"id": "c8ead8e9-199f-47c6-ad76-360b1ebdaa02",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"The algorithm should be slowest when *n* is prime, because then the `for` loop has to go all the way up to *n*. How long would it take for the largest 8-digit prime, 99,999,989?"
|
"The algorithm is slowest when *n* is prime, because the `for` loop has to go all the way up to *n*. How long would it take for the largest 8-digit prime, 99,999,989?"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": 6,
|
||||||
"id": "7323d528-96d7-4c05-a05d-125e99605443",
|
"id": "7323d528-96d7-4c05-a05d-125e99605443",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@@ -230,8 +242,8 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"CPU times: user 1.92 s, sys: 6.64 ms, total: 1.93 s\n",
|
"CPU times: user 1.9 s, sys: 18.4 ms, total: 1.92 s\n",
|
||||||
"Wall time: 1.93 s\n"
|
"Wall time: 1.92 s\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -240,7 +252,7 @@
|
|||||||
"99999989"
|
"99999989"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 5,
|
"execution_count": 6,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@@ -264,7 +276,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": 7,
|
||||||
"id": "b90b5407-4666-4925-99d2-6a3a6b192fac",
|
"id": "b90b5407-4666-4925-99d2-6a3a6b192fac",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -275,7 +287,7 @@
|
|||||||
" \"\"\"The largest prime that evenly divides n.\n",
|
" \"\"\"The largest prime that evenly divides n.\n",
|
||||||
" Find the smallest prime p that evenly divides n, \n",
|
" Find the smallest prime p that evenly divides n, \n",
|
||||||
" and return the maximum of p and the largest prime factor of n/p.\n",
|
" and return the maximum of p and the largest prime factor of n/p.\n",
|
||||||
" For prime n and for 1, return n.\"\"\"\n",
|
" If n is prime or if n = 1, this will return n.\"\"\"\n",
|
||||||
" for p in range(2, int(sqrt(n) + 1)): # <<<< only need to go up to √n\n",
|
" for p in range(2, int(sqrt(n) + 1)): # <<<< only need to go up to √n\n",
|
||||||
" if n % p == 0: # n is composite\n",
|
" if n % p == 0: # n is composite\n",
|
||||||
" return max(p, largest_prime_factor(n // p))\n",
|
" return max(p, largest_prime_factor(n // p))\n",
|
||||||
@@ -292,17 +304,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 7,
|
"execution_count": 8,
|
||||||
"id": "4026dc87-a0aa-4c75-b92a-96ec24cda1b7",
|
"id": "4026dc87-a0aa-4c75-b92a-96ec24cda1b7",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"'all tests pass'"
|
"[11, 'out of', 11, 'tests pass']"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 7,
|
"execution_count": 8,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@@ -321,7 +333,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 8,
|
"execution_count": 9,
|
||||||
"id": "d3d0c13e-5c01-4112-b372-60f7eb302d25",
|
"id": "d3d0c13e-5c01-4112-b372-60f7eb302d25",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@@ -329,8 +341,8 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"CPU times: user 238 μs, sys: 1 μs, total: 239 μs\n",
|
"CPU times: user 196 μs, sys: 0 ns, total: 196 μs\n",
|
||||||
"Wall time: 241 μs\n"
|
"Wall time: 196 μs\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -339,7 +351,7 @@
|
|||||||
"99999989"
|
"99999989"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 8,
|
"execution_count": 9,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@@ -353,14 +365,14 @@
|
|||||||
"id": "82b008ea-f6b5-4bcd-8768-09c8dab089cb",
|
"id": "82b008ea-f6b5-4bcd-8768-09c8dab089cb",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"As advertised, this is about 10,000 times faster.\n",
|
"As predicted, this is about 10,000 times faster.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"We should be able to handle a 16-digit prime in about 2 seconds:"
|
"We should be able to handle a 16-digit prime in about 2 seconds:"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 9,
|
"execution_count": 10,
|
||||||
"id": "9b6030ef-626a-4195-aedb-ef2edac65da4",
|
"id": "9b6030ef-626a-4195-aedb-ef2edac65da4",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@@ -368,8 +380,8 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"CPU times: user 2.05 s, sys: 7.3 ms, total: 2.05 s\n",
|
"CPU times: user 1.96 s, sys: 19.3 ms, total: 1.97 s\n",
|
||||||
"Wall time: 2.06 s\n"
|
"Wall time: 1.97 s\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -378,7 +390,7 @@
|
|||||||
"9927935178558959"
|
"9927935178558959"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 9,
|
"execution_count": 10,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@@ -395,24 +407,24 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"## Imperative versus Declarative (or Functional) Style\n",
|
"## Imperative versus Declarative (or Functional) Style\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Our definition of largest_prime_factor mixed paradigms, using some imperative features (a for loop with a return in the middle) and some functional (an implementation of the equation `largest_prime_factor(n) = max(p, largest_prime_factor(n // p))`).\n",
|
"Our definition of largest_prime_factor mixed paradigms, using some [imperative](https://en.wikipedia.org/wiki/Imperative_programming) features (a for loop with a return in the middle) and some [functional](https://en.wikipedia.org/wiki/Functional_programming) features (an implementation of the equation `largest_prime_factor(n) = max(p, largest_prime_factor(n // p))`).\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Here's what it might look like if we leaned into the functional style more, making the equation more explicit:"
|
"Here's what it might look like if we leaned into the functional style more, making the equation more explicit:"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 10,
|
"execution_count": 11,
|
||||||
"id": "0308612c-6860-49b0-bcd6-856fa08133b1",
|
"id": "0308612c-6860-49b0-bcd6-856fa08133b1",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"'all tests pass'"
|
"[11, 'out of', 11, 'tests pass']"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 10,
|
"execution_count": 11,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@@ -422,7 +434,7 @@
|
|||||||
" \"\"\"The largest prime that evenly divides n.\n",
|
" \"\"\"The largest prime that evenly divides n.\n",
|
||||||
" Find the smallest prime p that evenly divides n, \n",
|
" Find the smallest prime p that evenly divides n, \n",
|
||||||
" and return the maximum of p and the largest prime factor of n/p.\n",
|
" and return the maximum of p and the largest prime factor of n/p.\n",
|
||||||
" For prime n and for 1, return n.\"\"\"\n",
|
" If n is prime or if n = 1, this will return n.\"\"\"\n",
|
||||||
" p = smallest_prime_factor(n)\n",
|
" p = smallest_prime_factor(n)\n",
|
||||||
" return 1 if n == 1 else max(p, largest_prime_factor(n // p))\n",
|
" return 1 if n == 1 else max(p, largest_prime_factor(n // p))\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -443,17 +455,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 13,
|
"execution_count": 12,
|
||||||
"id": "b8907a8f-872f-4531-825c-fae9c70211c1",
|
"id": "b8907a8f-872f-4531-825c-fae9c70211c1",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"'all tests pass'"
|
"[11, 'out of', 11, 'tests pass']"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 13,
|
"execution_count": 12,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@@ -463,7 +475,7 @@
|
|||||||
" \"\"\"The largest prime that evenly divides n.\n",
|
" \"\"\"The largest prime that evenly divides n.\n",
|
||||||
" Find the smallest prime p that evenly divides n, \n",
|
" Find the smallest prime p that evenly divides n, \n",
|
||||||
" and return the maximum of p and the largest prime factor of n/p.\n",
|
" and return the maximum of p and the largest prime factor of n/p.\n",
|
||||||
" For prime n and for 1, return n.\"\"\"\n",
|
" If n is prime or if n = 1, this will return n.\"\"\"\n",
|
||||||
" largest = 1\n",
|
" largest = 1\n",
|
||||||
" p = 2\n",
|
" p = 2\n",
|
||||||
" while p * p <= n:\n",
|
" while p * p <= n:\n",
|
||||||
@@ -475,21 +487,13 @@
|
|||||||
" \n",
|
" \n",
|
||||||
"tests()"
|
"tests()"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "5a3de62a-5e7a-4458-b754-6b2ab50e5fb9",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": []
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "Python [conda env:base] *",
|
"display_name": "Python 3 (ipykernel)",
|
||||||
"language": "python",
|
"language": "python",
|
||||||
"name": "conda-base-py"
|
"name": "python3"
|
||||||
},
|
},
|
||||||
"language_info": {
|
"language_info": {
|
||||||
"codemirror_mode": {
|
"codemirror_mode": {
|
||||||
|
|||||||
@@ -229,7 +229,7 @@
|
|||||||
"|11|2,5 vs 4,11|1,3 vs 6,12|7,9 vs 8,10|\n",
|
"|11|2,5 vs 4,11|1,3 vs 6,12|7,9 vs 8,10|\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"||1|2|3|4|5|6|7|8|9|10|11|12|Total|\n",
|
"| |1|2|3|4|5|6|7|8|9|10|11|12|Total|\n",
|
||||||
"|--|--|--|--|--|--|--|--|--|--|--|--|--|--|\n",
|
"|--|--|--|--|--|--|--|--|--|--|--|--|--|--|\n",
|
||||||
"|**1**|-|3|1|3|1|2|2|1|2|1|3|3|11|\n",
|
"|**1**|-|3|1|3|1|2|2|1|2|1|3|3|11|\n",
|
||||||
"|**2**|3|-|2|2|3|2|1|2|2|2|2|1|11|\n",
|
"|**2**|3|-|2|2|3|2|1|2|2|2|2|1|11|\n",
|
||||||
@@ -255,16 +255,16 @@
|
|||||||
"|1|1,2 vs 3,4|5,6 vs 11,12|9,10 vs 7,8|\n",
|
"|1|1,2 vs 3,4|5,6 vs 11,12|9,10 vs 7,8|\n",
|
||||||
"|2|9,11 vs 4,12|8,10 vs 2,6|1,3 vs 5,7|\n",
|
"|2|9,11 vs 4,12|8,10 vs 2,6|1,3 vs 5,7|\n",
|
||||||
"|3|7,12 vs 2,3|5,9 vs 4,6|8,11 vs 1,10|\n",
|
"|3|7,12 vs 2,3|5,9 vs 4,6|8,11 vs 1,10|\n",
|
||||||
"|4|2,4 vs 6,11|5,12 vs 7,10|\n",
|
"|4|2,4 vs 6,11|5,12 vs 7,10||\n",
|
||||||
"|5|4,7 vs 2,9|6,12 vs 3,8|\n",
|
"|5|4,7 vs 2,9|6,12 vs 3,8||\n",
|
||||||
"|6|1,9 vs 2,10|3,6 vs 7,11|4,5 vs 8,12|\n",
|
"|6|1,9 vs 2,10|3,6 vs 7,11|4,5 vs 8,12|\n",
|
||||||
"|7|5,8 vs 2,12|6,7 vs 4,10|1,11 vs 3,9|\n",
|
"|7|5,8 vs 2,12|6,7 vs 4,10|1,11 vs 3,9|\n",
|
||||||
"|8|1,12 vs 6,9|3,7 vs 4,8|5,10 vs 2,11|\n",
|
"|8|1,12 vs 6,9|3,7 vs 4,8|5,10 vs 2,11|\n",
|
||||||
"|9|2,5 vs 1,6|3,10 vs 4,9|\n",
|
"|9|2,5 vs 1,6|3,10 vs 4,9||\n",
|
||||||
"|10|3,11 vs 2,8|1,5 vs 7,9|\n",
|
"|10|3,11 vs 2,8|1,5 vs 7,9||\n",
|
||||||
"|11|3,12 vs 10,11|6,8 vs 1,7|\n",
|
"|11|3,12 vs 10,11|6,8 vs 1,7||\n",
|
||||||
"|12|3,5 vs 6,10|9,12 vs 2,7|1,8 vs 4,11|\n",
|
"|12|3,5 vs 6,10|9,12 vs 2,7|1,8 vs 4,11|\n",
|
||||||
"|13|5,11 vs 8,9|1,4 vs 10,12|\n",
|
"|13|5,11 vs 8,9|1,4 vs 10,12||\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"||1|2|3|4|5|6|7|8|9|10|11|12|Total|\n",
|
"||1|2|3|4|5|6|7|8|9|10|11|12|Total|\n",
|
||||||
|
|||||||
259
ipynb/RationalPi.ipynb
Normal file
259
ipynb/RationalPi.ipynb
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "5b025dd9-9345-402d-9be0-dd0c17842915",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"<div align=\"right\" style=\"text-align: right\"><i>Peter Norvig<br>May 2026</i></div>\n",
|
||||||
|
"\n",
|
||||||
|
"# Fractions approximating π\n",
|
||||||
|
"\n",
|
||||||
|
"The number π is irrational, which means that it cannot be represented exactly by a fraction. But some fractions, such as 22/7, are known to come close to π. In this notebook, we look for fractions that approximate π even more closely than 22/7.\n",
|
||||||
|
"\n",
|
||||||
|
"If we want to know *what's the best fraction approximation to π with a denominator no more than a given number of digits?* we can try every possible denominator up to the given number of digits, compute the best numerator (and hence the best fraction) for each denominator, and choose the resulting fraction that minimizes the distance to the target, π (or if we want, any target):"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"id": "00c9ebd9-ee55-4dcb-917a-9c7a098d3816",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from fractions import Fraction\n",
|
||||||
|
"from math import pi\n",
|
||||||
|
"\n",
|
||||||
|
"def approximation(target=pi, digits=6) -> Fraction:\n",
|
||||||
|
" \"\"\"The fraction best approximating `target` whose denominator has no more than `digits` digits.\"\"\"\n",
|
||||||
|
" denominators = range(1, 10 ** digits)\n",
|
||||||
|
" fractions = (Fraction(round(target * d), d) for d in denominators)\n",
|
||||||
|
" return min(fractions, key=lambda x: abs(target - x))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "49db7449-1f81-4a7f-842a-84348dc5f16a",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"For example, here are the best approximations with one- and three-digit denominators:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"id": "de87500e-62cf-48fe-adee-3625f4cf6742",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"Fraction(22, 7)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"approximation(pi, 1)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 3,
|
||||||
|
"id": "3e9e799a-437a-45ff-8182-3d8d3342fe3a",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"Fraction(355, 113)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 3,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"approximation(pi, 3)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "4408e472-e7e6-4cc7-8a6b-790a55860bd3",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"We can make a pretty report showing the best approximations to π with 1, 2, 3, 4, and 5-digit denominators:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"id": "59faedd9-4899-4ccd-858b-fb5e4032a0cd",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def report(approximator=approximation, target=pi, d_range=range(1, 6)) -> str:\n",
|
||||||
|
" \"\"\"For each `d` in `d_range`, print a description of how close \n",
|
||||||
|
" the fraction `approximator(target, d)` is to `target`.\"\"\"\n",
|
||||||
|
" for d in d_range:\n",
|
||||||
|
" r = approximator(target, d)\n",
|
||||||
|
" print(f'{r:^22} = {r:.25f} (error {r-target:+6.0e})')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"id": "24447e10-a58f-43f2-93e5-3b058c098096",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
" 22/7 = 3.1428571428571428571428571 (error +1e-03)\n",
|
||||||
|
" 311/99 = 3.1414141414141414141414141 (error -2e-04)\n",
|
||||||
|
" 355/113 = 3.1415929203539823008849558 (error +3e-07)\n",
|
||||||
|
" 355/113 = 3.1415929203539823008849558 (error +3e-07)\n",
|
||||||
|
" 312689/99532 = 3.1415926536189366233975003 (error +3e-11)\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"report()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "5f21ad7f-193b-412e-b175-4cf9975cffd2",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"(The approximation 355/113 is so good that no 4-digit-denominator is better. You can think of 3550/1130 as the best 4-digit approximation.)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "9c035f0d-5cb8-4092-8ed1-883f9a9dd30d",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Faster, Better Approximations\n",
|
||||||
|
"\n",
|
||||||
|
"A 5-digit denominator is the most that `approximation` can handle in under a second of run time. \n",
|
||||||
|
"\n",
|
||||||
|
"We can get better approximations much faster by iteratively improving a guess:\n",
|
||||||
|
"- The zeroth approximation to π is formed by rounding to the nearest integer, **3**.\n",
|
||||||
|
"- The first approximation to π is formed by adding 3 to an approximation of the remainder after rounding, 0.14159...\n",
|
||||||
|
" - Rounding the remainder would give us 0, so that doesn't help.\n",
|
||||||
|
" - Instead of rounding the remainder, use (1 / approximation(1 / remainder)).\n",
|
||||||
|
" - 1 / 0.14159... rounds to 7 (with remainder 0.06251...) so the first approximation is **3 + (1/7) = 22/7**.\n",
|
||||||
|
"- The second approximation to π is formed by adding in an approximation of 0.06251...\n",
|
||||||
|
" - 1 / 0.06251... rounds to 16, so the second approximation is **3 + (1/(7 + 1/16)) = 355/113**.\n",
|
||||||
|
" - You can repeat the approximation process to any depth.\n",
|
||||||
|
" \n",
|
||||||
|
"We can implement it like this:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 6,
|
||||||
|
"id": "f81761ad-1b21-4dce-9fba-9621447617d1",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"PI = Fraction(\"3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803\")\n",
|
||||||
|
"\n",
|
||||||
|
"def fast_approximation(target: Fraction, depth: int) -> Fraction:\n",
|
||||||
|
" \"\"\"Approximate `target` by taking the whole part plus an approximation to the remainder.\n",
|
||||||
|
" Repeat `depth` times (or stop when there is no remainder).\n",
|
||||||
|
" Use (1 / fast_approximation(1 / remainder)), because remainder < 1 and (1 / remainder) > 1.\"\"\"\n",
|
||||||
|
" whole = round(target)\n",
|
||||||
|
" remainder = target - whole\n",
|
||||||
|
" if depth == 0 or remainder == 0:\n",
|
||||||
|
" return Fraction(whole)\n",
|
||||||
|
" else:\n",
|
||||||
|
" return whole + (1 / fast_approximation(1 / remainder, depth - 1))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "7e3c32d2-66f7-450f-9dc3-e5034dfd09c5",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"This gives an approximation accurate to 22 digits after 14 iterations, and takes just milliseconds to run:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 7,
|
||||||
|
"id": "ba7e0c79-515e-48c8-9f7b-a4a99734b9be",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
" 3 = 3.0000000000000000000000000 (error -1e-01)\n",
|
||||||
|
" 22/7 = 3.1428571428571428571428571 (error +1e-03)\n",
|
||||||
|
" 355/113 = 3.1415929203539823008849558 (error +3e-07)\n",
|
||||||
|
" 104348/33215 = 3.1415926539214210447087159 (error +3e-10)\n",
|
||||||
|
" 312689/99532 = 3.1415926536189366233975003 (error +3e-11)\n",
|
||||||
|
" 1146408/364913 = 3.1415926535914039784825424 (error +2e-12)\n",
|
||||||
|
" 5419351/1725033 = 3.1415926535898153832419438 (error +2e-14)\n",
|
||||||
|
" 80143857/25510582 = 3.1415926535897926593756269 (error -6e-16)\n",
|
||||||
|
" 245850922/78256779 = 3.1415926535897931602832772 (error -8e-17)\n",
|
||||||
|
" 411557987/131002976 = 3.1415926535897932578264482 (error +2e-17)\n",
|
||||||
|
" 1068966896/340262731 = 3.1415926535897932353925649 (error -3e-18)\n",
|
||||||
|
" 2549491779/811528438 = 3.1415926535897932390140098 (error +6e-19)\n",
|
||||||
|
"6167950454/1963319607 = 3.1415926535897932383863775 (error -8e-20)\n",
|
||||||
|
"21053343141/6701487259 = 3.1415926535897932384623817 (error -3e-22)\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"report(fast_approximation, PI, range(14))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "c4f1404b-a9b2-4aaa-be83-d34bab26d734",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"It turns out there is a name for this approach: it is the [continued fraction approximation to π](https://en.wikipedia.org/wiki/Pi#Continued_fractions). \n",
|
||||||
|
"\n",
|
||||||
|
"Note: it is more traditional to use `whole = int(target)` rather than `whole = round(target)` to generate the continued fractions. Using `round` gives better fractions in fewer itera, but using `int` has the nice property that all the bits we add are positive."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "4ea1db23-b668-4854-86ea-337462a18a8b",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python [conda env:base] *",
|
||||||
|
"language": "python",
|
||||||
|
"name": "conda-base-py"
|
||||||
|
},
|
||||||
|
"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.13.9"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 5
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"# The Concordance Assignment\n",
|
"# The Concordance Assignment\n",
|
||||||
"\n",
|
"\n",
|
||||||
"> *Using the [`Snobol`](http://www.snobol4.org/) language, read lines of text from the standard input and print a *concordance*, which is an alphabetized list of words in the text, with the line number(s) where each word appears. Words with different capitalization (like \"A\" and \"a\") should be merged into one entry.*\n",
|
"> *Using the [`Snobol`](http://www.snobol4.org/) language, read lines of text from the standard input and print a **concordance**, which is an alphabetized list of words in the text, with the line number(s) where each word appears. Words with different capitalization (like \"A\" and \"a\") should be merged into one entry.*\n",
|
||||||
"\n",
|
"\n",
|
||||||
"After studying Snobol a bit, I realized that the expected solution was along these lines:\n",
|
"After studying Snobol a bit, I realized that the expected solution was along these lines:\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|||||||
@@ -294,8 +294,8 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def guess_row(guess) -> Tuple[Word, int, float, int]:\n",
|
"def guess_row(guess) -> Tuple[Word, int, float]:\n",
|
||||||
" \"\"\"A tuple of a (guess word, nuber of guaranteed wins, expected wins, maximum bin size).\"\"\"\n",
|
" \"\"\"A tuple of a (guess word, number of guaranteed wins, expected wins).\"\"\"\n",
|
||||||
" B = bins([guess], words)\n",
|
" B = bins([guess], words)\n",
|
||||||
" return (guess, sum(len(bin) == 1 for bin in B), sum(1 / len(bin) for bin in B))\n",
|
" return (guess, sum(len(bin) == 1 for bin in B), sum(1 / len(bin) for bin in B))\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|||||||
938
ipynb/lispy.ipynb
Normal file
938
ipynb/lispy.ipynb
Normal file
@@ -0,0 +1,938 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "828d21f7-0a3b-4024-b3d5-306ea56a3214",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"<div align=\"right\" style=\"text-align: right\"><i>Peter Norvig</i></div>\n",
|
||||||
|
"\n",
|
||||||
|
"# (How to Write a (Lisp) Interpreter (in Python))\n",
|
||||||
|
"\n",
|
||||||
|
"This notebook describes how (and why) to implement computer language interpreters in general, and in particular an interpreter for most of the [**Scheme**](https://www.scheme.org/) dialect of [**Lisp**](https://en.wikipedia.org/wiki/Lisp_(programming_language%29). I call my language and interpreter **Lispy** because it is Lisp implemented in Python. \n",
|
||||||
|
"\n",
|
||||||
|
"Why should interpreters and compilers matter to you? As [Steve Yegge said](https://steve-yegge.blogspot.com/2007/06/rich-programmer-food.html?), \"If you don't know how compilers work, then you don't know how computers work.\" Yegge describes 8 problems that can be solved with compilers (or equally well with interpreters, or with Yegge's typical heavy dosage of cynicism).\n",
|
||||||
|
"\n",
|
||||||
|
"## Syntax and Semantics of Programs\n",
|
||||||
|
"\n",
|
||||||
|
"The **syntax** of a language is the arrangement of characters to form correct statements or expressions. For example, in the language of mathematical expressions (and in many programming languages and handheld calculators), the syntax for computing one plus two is \"1 + 2\". The **semantics** of a language determines what it means: what computations it describes, and ultimately what answer(s) it computes. We say that \"1 + 2\" *evaluates* to 3, and write that as \"1 + 2\" ⇒ 3. \n",
|
||||||
|
"\n",
|
||||||
|
"If you are familiar with languages such as Python or Java, you may find Scheme syntax to be unusual. Consider:\n",
|
||||||
|
"\n",
|
||||||
|
"<table style=\"border-collapse: collapse; border: 2px solid black;\">\n",
|
||||||
|
" <thead>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th style=\"border: 1px solid black; padding: 10px; text-align: left;\">Java</th>\n",
|
||||||
|
" <th style=\"border: 1px solid black; padding: 10px; text-align: left;\">Lisp</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <td style=\"border: 1px solid black; padding: 10px; vertical-align: top;\">\n",
|
||||||
|
"<pre style=\"margin: 0; font-family: monospace;\"><code>if (x.val() > 0) {\n",
|
||||||
|
" return fn(A[i] + 3 * i,\n",
|
||||||
|
" new String[] {\"one\", \"two\"});\n",
|
||||||
|
"}</code></pre>\n",
|
||||||
|
" </td>\n",
|
||||||
|
" <td style=\"border: 1px solid black; padding: 10px; vertical-align: top;\">\n",
|
||||||
|
"<pre style=\"margin: 0; font-family: monospace;\"><code>(if (> (val x) 0)\n",
|
||||||
|
" (fn (+ (aref A i) (* 3 i))\n",
|
||||||
|
" (quote (one two))))</code></pre>\n",
|
||||||
|
" </td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table> \n",
|
||||||
|
"\n",
|
||||||
|
"Java has a wide variety of syntactic conventions (keywords, infix operators, four kinds of brackets, operator precedence, dot notation, quotes, commas, semicolons), but Scheme syntax is much simpler:\n",
|
||||||
|
"Scheme programs consist solely of expressions; there is no statement/expression distinction.\n",
|
||||||
|
"Numbers (e.g. 1) and symbols (e.g. A) are called **atomic expressions**; they cannot be broken into pieces. These are similar to their Java counterparts, except that in Scheme, operators such as `+` and `>` are symbols too, and are treated the same way as `A` and `fn`.\n",
|
||||||
|
"Everything else is a **list expression**: a \"(\", followed by zero or more expressions, followed by a \")\". The first element of the list expression determines what it means:\n",
|
||||||
|
"- A list starting with a keyword, e.g. `(if ...)`, is a **special form**; the meaning depends on the keyword.\n",
|
||||||
|
"- A list starting with a non-keyword, e.g. `(max x y)`, is a function call: the function `max` is applied to the arguments `x` and `y` to compute a value.\n",
|
||||||
|
"\n",
|
||||||
|
"The beauty of Scheme is that the full language only needs 5 keywords and 8 syntactic forms. In comparison, Python has 35 keywords and 110 syntactic forms, and Java has 50 keywords and 133 syntactic forms. All those parentheses may seem intimidating, but Scheme syntax has the virtues of simplicity and consistency. (Some have joked that \"Lisp\" stands for \"**L**ots of **I**rritating **S**illy **P**arentheses\"; I think it stand for \"**L**isp **I**s **S**yntactically **P**ure\".)\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"# Language 1: Lispy Calculator\n",
|
||||||
|
"\n",
|
||||||
|
"We won't tackle all of Scheme right away; instead we'll start with a subset of Scheme I call **Lispy Calculator**. Lispy Calculator lets you do any computation you could do on a typical calculator—as long as you are comfortable with prefix notation. And while many calculators let you store and retrieve a value from a fixed set of registers (e.g. A, B, or C), Lispy Calculator let's you define and use any number of variables with any names you choose. Here's an example program that computes the area of a circle of radius 10, using the formula π r<sup>2</sup>\n",
|
||||||
|
"\n",
|
||||||
|
" (begin\n",
|
||||||
|
" (define r 10)\n",
|
||||||
|
" (* pi (* r r)))\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"Here is a table of all the allowable expressions in the Lispy Calculator Language. In the Syntax column of this table, *symbol* must be a symbol, *number* must be an integer or floating point number, and the other italicized words can be any expression. The notation *exp...* means zero or more repetitions of *exp*.\n",
|
||||||
|
"\n",
|
||||||
|
"|Expression\t|Syntax\t|Example|Semantics|\n",
|
||||||
|
"|-----------|-------|-------|-------------|\n",
|
||||||
|
"|constant \t|*number*\t|`12` or `-3.45e+6`|A number evaluates to itself.|\n",
|
||||||
|
"|variable |\t*symbol*\t|`r`|A symbol is interpreted as a variable name; its value is the variable's value.|\n",
|
||||||
|
"|definition\t|`(define` *symbol exp*`}`\t|`(define r 10)`|Define a new variable and give it the value of the expression *exp*.|\n",
|
||||||
|
"|procedure call\t|`(`*proc exp*...`)`\t|`(sqrt (* 2 8))` ⇒ 4.0|Proc's value (a function) is applied to the argument values.|\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"Let's get some imports out of the way, and be explicit about how Scheme objects are represented in Python:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"id": "e1c3cef0-d091-433e-a2c0-0959df3cee0d",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from numbers import Number\n",
|
||||||
|
"import math\n",
|
||||||
|
"import operator as op\n",
|
||||||
|
"\n",
|
||||||
|
"Symbol = str # A Scheme symbol is implemented as a Python str\n",
|
||||||
|
"Atom = Symbol | Number # A Scheme atom is a Symbol or Number\n",
|
||||||
|
"List = list # A Scheme list is implemented as a Python list\n",
|
||||||
|
"Exp = Atom | List # A Scheme expression is an Atom or List\n",
|
||||||
|
"Env = dict # A Scheme environment is a dictionary mapping of {variable: value}"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "b5c1ff1c-15e1-47d2-bfc8-a008ecc5ff13",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## The core of Lisp: eval \n",
|
||||||
|
"\n",
|
||||||
|
"Here is the core of the interpreter, `eval`. It takes as input an expression, `exp`, and an **environment** that specifies the values of variables. It returns the value of the expression. These few lines are what what [Alan Kay called](https://queue.acm.org/detail.cfm?id=1039523) \"the Maxwell's Equations of Software.\"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"id": "3b081873-6ae7-4d73-830d-c441cd196cbc",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def eval(exp: Exp, env: Env) -> object:\n",
|
||||||
|
" \"\"\"Evaluate an expression in an environment.\"\"\"\n",
|
||||||
|
" match exp:\n",
|
||||||
|
" case Number(): # number evaluates to itself \n",
|
||||||
|
" return exp\n",
|
||||||
|
" case Symbol(): # variable evaluates to its value in environment\n",
|
||||||
|
" return env[exp]\n",
|
||||||
|
" case ('define', Symbol(name), val): # definition adds name to the environment\n",
|
||||||
|
" env[name] = eval(val, env)\n",
|
||||||
|
" return name\n",
|
||||||
|
" case (proc, *args): # procedure call\n",
|
||||||
|
" func = eval(proc, env)\n",
|
||||||
|
" vals = [eval(arg, env) for arg in args]\n",
|
||||||
|
" return func(*vals)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "e9ae14da-9668-405a-8c5c-2a7186e98cb4",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Global Environment\n",
|
||||||
|
"\n",
|
||||||
|
"We mentioned that an **environment** is a mapping from variable names to their values. We will define a default global environment. `ENV`, containing values for the names of a bunch of standard functions like `sqrt` and `max`, as well as operators like `+` and `>`, which are implemented as procedures in Lisp. (Scheme's name for `print` is `display`; the function `unparse` will be defined later.)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 3,
|
||||||
|
"id": "ce21a511-1089-4d70-9c9a-8825c3d63b17",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"ENV = {\n",
|
||||||
|
" **vars(math), # sqrt, sin, cos, etc.\n",
|
||||||
|
" '+':op.add, '-':op.sub, '*':op.mul, '/':op.truediv, \n",
|
||||||
|
" '>':op.gt, '<':op.lt, '>=':op.ge, '<=':op.le, '=':op.eq, \n",
|
||||||
|
" 'eq?': op.is_, 'equal?': op.eq,\n",
|
||||||
|
" 'abs': abs,\n",
|
||||||
|
" 'append': op.add, \n",
|
||||||
|
" 'apply': lambda proc, args: proc(*args),\n",
|
||||||
|
" 'begin': lambda *x: x[-1],\n",
|
||||||
|
" 'cons': lambda x,y: [x] + y,\n",
|
||||||
|
" 'display': lambda x: print(unparse(x)),\n",
|
||||||
|
" 'expt': pow,\n",
|
||||||
|
" 'first': lambda x: x[0],\n",
|
||||||
|
" 'length': len, \n",
|
||||||
|
" 'list': lambda *x: List(x), \n",
|
||||||
|
" 'list?': lambda x: isinstance(x, list), \n",
|
||||||
|
" 'map': lambda f, *args: list(map(f, *args)),\n",
|
||||||
|
" 'max': max, \n",
|
||||||
|
" 'min': min,\n",
|
||||||
|
" 'not': op.not_,\n",
|
||||||
|
" 'null?': lambda x: x == [], \n",
|
||||||
|
" 'number?': lambda x: isinstance(x, Number), \n",
|
||||||
|
" 'procedure?': callable,\n",
|
||||||
|
" 'rest': lambda x: x[1:], \n",
|
||||||
|
" 'round': round,\n",
|
||||||
|
" 'symbol?': lambda x: isinstance(x, Symbol),\n",
|
||||||
|
" }"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "edafbbc3-ae0b-4705-859e-3fcf2f10fdad",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"(*Note:* because I am not implementing all the features of Scheme (such as [continuations](https://groups.csail.mit.edu/mac/projects/info/schemedocs/ref-manual/html/scheme_122.html)), I can get away with defining `begin` as a function rather than a special form.)\n",
|
||||||
|
"\n",
|
||||||
|
"## Parsing\n",
|
||||||
|
"\n",
|
||||||
|
"How do we get from a sequence of characters to the abstract syntax tree that `eval` expects? The function `parse` does the job, in two steps: \n",
|
||||||
|
"1. **Lexical analysis**: the function `tokenize` breaks the characters into tokens (such as the keyword `\"if\"` or the number `\"10\"`).\n",
|
||||||
|
"2. **Syntactic analysis**: the function `parse_tokens` converts the tokens into an expression."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"id": "209b7574-1cad-469e-b735-06f8e18d699d",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def parse(program: str) -> Exp:\n",
|
||||||
|
" \"\"\"Read a Scheme expression from a string.\n",
|
||||||
|
" First split the program into tokens, then read from the token list.\"\"\"\n",
|
||||||
|
" return parse_tokens(tokenize(program))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "1b6a1fb3-4765-42c2-9278-a374fa30f5af",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"There are many tools for lexical analysis (such as Mike Lesk and Eric Schmidt's [lex](https://en.wikipedia.org/wiki/Lex_%28software%29)), most of which define tokens as a class containing a token kind and a token string. But Lisp is so simple that there are really only three types of tokens: left paren, right paren, and everything else. So `str.split` can do the job (with a little help):"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"id": "48875a7a-3c86-4322-9307-3592ab327924",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def tokenize(chars: str) -> list[str]:\n",
|
||||||
|
" \"\"\"Convert a string of characters into a list of tokens.\n",
|
||||||
|
" (Put spaces around parens, then split on spaces.)\"\"\"\n",
|
||||||
|
" return chars.replace('(', ' ( ').replace(')', ' ) ').split()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "64d2de32-6e7f-43ba-b6db-eb1eff397ff2",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"`parse_tokens` looks at the first token; if it is a `)` that's a syntax error. If it is a `(`, then we start building up a list of sub-expressions until we hit a matching `)`. Any non-parenthesis token must be an atom: first try to interpret it as a number, and failing that, it must be a symbol. "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 6,
|
||||||
|
"id": "c2677c70-f08f-49ff-b167-0cb492ec124f",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def parse_tokens(tokens: list[str]) -> Exp:\n",
|
||||||
|
" \"\"\"Read an expression from a list of tokens, mutating the list.\"\"\"\n",
|
||||||
|
" if not tokens:\n",
|
||||||
|
" raise SyntaxError('unexpected end of expression')\n",
|
||||||
|
" match (token := tokens.pop(0)):\n",
|
||||||
|
" case ')':\n",
|
||||||
|
" raise SyntaxError('unexpected \")\"')\n",
|
||||||
|
" case '(':\n",
|
||||||
|
" result = []\n",
|
||||||
|
" while tokens[0] != ')':\n",
|
||||||
|
" result.append(parse_tokens(tokens))\n",
|
||||||
|
" tokens.pop(0) # pop off the closing ')'\n",
|
||||||
|
" return result\n",
|
||||||
|
" case _:\n",
|
||||||
|
" try:\n",
|
||||||
|
" n = float(token)\n",
|
||||||
|
" return int(n) if n.is_integer() else n\n",
|
||||||
|
" except ValueError:\n",
|
||||||
|
" return token # symbol"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "a8191faa-a8ad-41dc-a1fa-a3e805b24a28",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Homoiconicity\n",
|
||||||
|
"\n",
|
||||||
|
"One of the defining features of Lisp is [**homoiconicity**](https://en.wikipedia.org/wiki/Homoiconicity), a fancy word derived from the Greek for \"same representation\" that refers to a language in which the internal representation of a program is the same as the external representation. In other words, a Lisp program is just a list, so all the functions for reading, manipulating and printing lists apply equally to programs. We've already defined `parse` to convert a string into an internal representation; now we'll define `unparse` to reverse the process:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 7,
|
||||||
|
"id": "62c5a9f4-5969-4646-ac64-fbc34027cadc",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def unparse(exp: Exp) -> str:\n",
|
||||||
|
" \"Convert a Python object back into a Scheme-readable string.\"\n",
|
||||||
|
" match exp:\n",
|
||||||
|
" case List(): return '(' + ' '.join(map(unparse, exp)) + ')'\n",
|
||||||
|
" case _: return str(exp)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "69764e26-0c13-4b05-86aa-cec9605865b6",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"We can see that parse and unparse are inverses:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 8,
|
||||||
|
"id": "9c5d310b-832e-494e-a141-b8eeaa221206",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"'(lambda (A i) (fn (+ (aref A i) (* 3 i))))'"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 8,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"unparse(parse(\"(lambda (A i) (fn (+ (aref A i) (* 3 i))))\"))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "cf6b5b61-f523-486a-b600-7a9aadc4c824",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Python has a module, `ast` (for \"abstract syntax tree\") that makes it possible to manipulate programs, but Python is not homoiconic. The internal representation of a program is quite different from the external representation:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 9,
|
||||||
|
"id": "0617fa61-7f37-4623-b431-fa44a3edb5e4",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Module(\n",
|
||||||
|
" body=[\n",
|
||||||
|
" Expr(\n",
|
||||||
|
" value=Lambda(\n",
|
||||||
|
" args=arguments(\n",
|
||||||
|
" args=[\n",
|
||||||
|
" arg(arg='A'),\n",
|
||||||
|
" arg(arg='i')]),\n",
|
||||||
|
" body=Call(\n",
|
||||||
|
" func=Name(id='fn', ctx=Load()),\n",
|
||||||
|
" args=[\n",
|
||||||
|
" BinOp(\n",
|
||||||
|
" left=Subscript(\n",
|
||||||
|
" value=Name(id='A', ctx=Load()),\n",
|
||||||
|
" slice=Name(id='i', ctx=Load()),\n",
|
||||||
|
" ctx=Load()),\n",
|
||||||
|
" op=Add(),\n",
|
||||||
|
" right=BinOp(\n",
|
||||||
|
" left=Constant(value=3),\n",
|
||||||
|
" op=Mult(),\n",
|
||||||
|
" right=Name(id='i', ctx=Load())))])))])\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import ast\n",
|
||||||
|
"print(ast.dump(ast.parse(\"lambda A, i: fn(A[i] + 3 * i)\"), indent=4))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "c568f646-4f7e-4c13-806d-5bfc7fc98933",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Batch Processing\n",
|
||||||
|
"\n",
|
||||||
|
"In **batch processing** an entire program is read, parsed, and evaluated in one step, with no human in the loop."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 10,
|
||||||
|
"id": "3a96b511-30da-407b-9137-4b79bc40c367",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def batch(program: str) -> None:\n",
|
||||||
|
" \"\"\"Parse the program, evaluate it, and print the result.\"\"\"\n",
|
||||||
|
" print(unparse(eval(parse(program), ENV)))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "8aa89ec1-7f62-4797-8e70-da97e74a7b88",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Here is a sample program and the result of running it using `batch`:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 11,
|
||||||
|
"id": "69509c3a-2c1e-435e-8563-9a9a82cfc75f",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"program1 = \"\"\"\n",
|
||||||
|
"(begin \n",
|
||||||
|
" (define r 10)\n",
|
||||||
|
" (* pi (* r r))) \"\"\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 12,
|
||||||
|
"id": "6447f9b9-a3f8-4465-a735-1be81217b94d",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"314.1592653589793\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"batch(program1)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "3ec8b0e9-e384-48fa-8539-2794114f2275",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"We can also see the intermediate steps of tokenizing and parsing the program:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 13,
|
||||||
|
"id": "75485bb1-9625-470e-bfa2-3e3c39cb43c0",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"['(',\n",
|
||||||
|
" 'begin',\n",
|
||||||
|
" '(',\n",
|
||||||
|
" 'define',\n",
|
||||||
|
" 'r',\n",
|
||||||
|
" '10',\n",
|
||||||
|
" ')',\n",
|
||||||
|
" '(',\n",
|
||||||
|
" '*',\n",
|
||||||
|
" 'pi',\n",
|
||||||
|
" '(',\n",
|
||||||
|
" '*',\n",
|
||||||
|
" 'r',\n",
|
||||||
|
" 'r',\n",
|
||||||
|
" ')',\n",
|
||||||
|
" ')',\n",
|
||||||
|
" ')']"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 13,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"tokenize(program1)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 14,
|
||||||
|
"id": "1fba56d9-e97b-4919-9a51-31e94c535361",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"['begin', ['define', 'r', 10], ['*', 'pi', ['*', 'r', 'r']]]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 14,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"parse(program1)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "ffe3866c-76ee-4a6e-b0d2-efb18b544c1e",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Interactive Processing\n",
|
||||||
|
"\n",
|
||||||
|
"One of Lisp's great legacies is the notion of an interactive loop: a way for a programmer to enter an expression, see the results, and then think of something new to try. This facilitates exploratory programming: instead of having to design every aspect of a complete program ahead of time, the programmer can experiment, learning as they go, step by step. So let's define the function `repl` (which stands for read-eval-print-loop):"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 15,
|
||||||
|
"id": "037afa47-c35e-416f-affb-aa219cfff935",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def repl(prompt='\\nlispy> ') -> None:\n",
|
||||||
|
" \"\"\"A read-eval-print loop.\"\"\"\n",
|
||||||
|
" print('lispy> read-eval-print loop – Type exit to exit')\n",
|
||||||
|
" while (expr := input(prompt)) != 'exit':\n",
|
||||||
|
" batch(expr)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "28cccf9e-0cf3-426b-9f12-61ac165f1e31",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Here is an example run of `repl()`:\n",
|
||||||
|
" \n",
|
||||||
|
" lispy> read-eval-print loop – Type exit to exit\n",
|
||||||
|
" lispy> (define r 10)\n",
|
||||||
|
" r\n",
|
||||||
|
" \n",
|
||||||
|
" lispy> (* pi (* r r))\n",
|
||||||
|
" 314.159265359\n",
|
||||||
|
" \n",
|
||||||
|
" lispy> (if (> (* 11 11) 120) (* 7 6) oops)\n",
|
||||||
|
" 42\n",
|
||||||
|
" \n",
|
||||||
|
" lispy> (list (+ 1 1) (+ 2 2) (* 2 3) (expt 2 3) (expt 2 (expt 2 2)))\n",
|
||||||
|
" (2 4 6 8 16\n",
|
||||||
|
"\n",
|
||||||
|
" lispy> exit\n",
|
||||||
|
"\n",
|
||||||
|
"You can experiment with `repl()` yourself by deleting the `#` and running the following cell. I left it commented out so that when you do the \"Run All Cells\" command on this notebook, it runs all the way through, without pausing to ask you to type in some Scheme expressions."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 16,
|
||||||
|
"id": "5286fcff-0152-4da7-8b70-d5ba1883ac4d",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"#repl()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "ed98aea1-201a-4532-9cf4-56aff0ba74e6",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Language 2: Full Lispy\n",
|
||||||
|
"\n",
|
||||||
|
"We will now extend our language with four new special forms, and one variant of the old `define` special form. This gived us a much more nearly-complete Scheme subset:\n",
|
||||||
|
"\n",
|
||||||
|
"|Expression\t|Syntax| Example|\tSemantics|\n",
|
||||||
|
"|-----------|------|--------|------------|\n",
|
||||||
|
"|conditional\t|(`if` *test then_part else_part*`)`|`(if (< x 0) (- x) x)`|\tEvaluate *test*; if true, evaluate and return *then part*; otherwise *else part*.|\n",
|
||||||
|
"|quotation\t|`(quote` *exp*`)`| `(quote (+ 1 2))` ⇒ `(+ 1 2)`|\tReturn the exp literally; do not evaluate it.|\n",
|
||||||
|
"|assignment\t|`(set!` *symbol exp*`)`| `(set! r2 (* r r))`|\tEvaluate *exp* and assign that value to *symbol*.|\n",
|
||||||
|
"|procedure\t|`(lambda (`*symbol...*`)` *exp*`)`|`(lambda (r) (* pi (* r r)))`|\tCreate an anonymous procedure.|\n",
|
||||||
|
"|definition | `(define (`*symbol*...`)` *body*`)`|`(defun (add1 x) (+ x 1)`| Define a named procedure.|\n",
|
||||||
|
"\n",
|
||||||
|
"- The `if` special form is similar to the `(x if test else y)` syntax in Python, although only `False` counts as false in Scheme.\n",
|
||||||
|
"- The `quote` special form allows you to build a literal data structure.\n",
|
||||||
|
"- The `set!` special form allows you to update the value of a previously-defined variable. This is different from `define`, which introduces a new variable in the curent environment (and sets its initial value).\n",
|
||||||
|
"- The `lambda` special form (an obscure name from Alonzo Church's [lambda calculus](https://en.wikipedia.org/wiki/Lambda_calculus)) creates a procedure (without giving it a name).\n",
|
||||||
|
"- The new option for `define` is just a shortcut for a regular `define` of a `lambda` expression.\n",
|
||||||
|
"\n",
|
||||||
|
"There are two equivalent ways of defining a procedure and giving it a name. Consider:\n",
|
||||||
|
"\n",
|
||||||
|
" (define (circle-area r) (* pi (* r r)))\n",
|
||||||
|
"\n",
|
||||||
|
" (define circle-area (lambda (r) (* pi (* r r)))\n",
|
||||||
|
"\n",
|
||||||
|
"Either way, `circle-area` is defined to take as its value a procedure that refers to the global variables `pi` and `*`, and takes a single parameter, `r`. Now we can call the procedure like this:\n",
|
||||||
|
"\n",
|
||||||
|
" (circle-area (+ 5 5))\n",
|
||||||
|
"\n",
|
||||||
|
"We want this call to return the value of `(* pi (* r r))` with `r` set to 10. But it wouldn't do to set `r` to 10 in the global environment. What if we were using `r` for some other purpose? Instead, we want to arrange for there to be a **local variable** named `r` that is only used during this call to `circle-area`. The process for calling a procedure introduces these new local variable(s), binding each symbol in the parameter list of the function to the corresponding value in the argument list of the function call. In this case, the result of the call is 314.159265359.\n",
|
||||||
|
" \n",
|
||||||
|
"\n",
|
||||||
|
"## Local Variables and Procedures\n",
|
||||||
|
"\n",
|
||||||
|
"To handle local variables, we will **nest** envronments. Local variables are defined in an environment that is \"inside\" another environment. We will use the convention: `env['_outer']` to refer to the outer environment of the nested environment `env`. When we evaluate (`circle-area (+ 5 5))`, we will fetch the procedure body, `(* pi (* r r))`, and evaluate it in an environment that has `r` as the sole local variable (with value 10), but also has the global environment as the `_outer` environment; it is there that we will find the values of `*` and `pi`. In the diagram, the inner environment is blue and the outer red:\n",
|
||||||
|
"\n",
|
||||||
|
"<p><table style=\"border: 3px solid red\" cellspacing=1 cellpadding=5><tr><td>\n",
|
||||||
|
"<tt>pi: 3.141592653589793\n",
|
||||||
|
"<br>*: <built-in function mul>\n",
|
||||||
|
"<br>...\n",
|
||||||
|
"<br>\n",
|
||||||
|
"<table style=\"border: 3px solid blue\" cellspacing=1 cellpadding=5>\n",
|
||||||
|
"<tr><td>r: 10\n",
|
||||||
|
"</table>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"\n",
|
||||||
|
"When we look up a variable in such a nested environment, we look first at the innermost level, but if we don't find the variable name there, we move to the next outer level. \n",
|
||||||
|
"\n",
|
||||||
|
"Here is the definition of the Procedure class:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 17,
|
||||||
|
"id": "1d9cc9fb-32df-41dc-9c6c-863c7a5ba5a6",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from dataclasses import dataclass\n",
|
||||||
|
"\n",
|
||||||
|
"@dataclass\n",
|
||||||
|
"class Procedure(object):\n",
|
||||||
|
" \"\"\"A user-defined Scheme procedure.\"\"\"\n",
|
||||||
|
" parms: list[Symbol]\n",
|
||||||
|
" body: Exp\n",
|
||||||
|
" env: Env\n",
|
||||||
|
" def __call__(self, *args) -> object: \n",
|
||||||
|
" env = Env(zip(self.parms, args), _outer=self.env)\n",
|
||||||
|
" return eval(self.body, env)\n",
|
||||||
|
" def __repr__(self) -> str: \n",
|
||||||
|
" return f'<Procedure{unparse(self.parms)}>'"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "7734c900-7d9c-4770-987a-30830989175d",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"We see that a procedure has three components: a list of parameter names, a body expression, and an environment that tells us what other variables are accessible from the body. For a procedure defined at the top level this will be the global environment, but it is also possible for a procedure to refer to the local variables of the environment in which it was defined (**not** the environment in which it is called).\n",
|
||||||
|
"\n",
|
||||||
|
"The function `find` is used to find the right environment for a variable: starting with the inner one and going out, find the first environment that mentions the variable name."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 18,
|
||||||
|
"id": "22fd9960-b288-4a01-94fe-faab8e8da8bf",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def find(var: Symbol, env: Env) -> Env:\n",
|
||||||
|
" \"\"\"Find the environment that contains the variable `var`.\"\"\"\n",
|
||||||
|
" return env if (var in env) else find(var, env['_outer'])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "3d0599c6-3a35-4fd8-b179-c970e8a36c4d",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"To see how these all go together, here is the new definition of `eval`:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 19,
|
||||||
|
"id": "afa69b35-bac3-459c-a0cc-b94656ab474c",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def eval(exp: Exp, env) -> object:\n",
|
||||||
|
" \"\"\"Evaluate an expression in an environment.\"\"\"\n",
|
||||||
|
" match exp:\n",
|
||||||
|
" case Symbol(): # variable reference\n",
|
||||||
|
" return find(exp, env)[exp]\n",
|
||||||
|
" case Number(): # constant \n",
|
||||||
|
" return exp\n",
|
||||||
|
" case ('if', test, then_, else_): # conditional evaluates one branch or the other\n",
|
||||||
|
" branch = (else_ if eval(test, env) is False else then_)\n",
|
||||||
|
" return eval(branch, env)\n",
|
||||||
|
" case ('define', (name, *parms), body): # procedure definition\n",
|
||||||
|
" env[name] = eval(['lambda', parms, body], env)\n",
|
||||||
|
" return name\n",
|
||||||
|
" case ('define', Symbol(name), val): # regular definition\n",
|
||||||
|
" env[name] = eval(val, env)\n",
|
||||||
|
" return name\n",
|
||||||
|
" case ('quote', constant): # constant expression\n",
|
||||||
|
" return constant\n",
|
||||||
|
" case ('set!', symbol, val): # variable assignment\n",
|
||||||
|
" find(symbol, env)[symbol] = eval(val, env)\n",
|
||||||
|
" return None\n",
|
||||||
|
" case ('lambda', parms, body): # create an anonymous procedure\n",
|
||||||
|
" return Procedure(parms, body, env)\n",
|
||||||
|
" case (proc, *args): # procedure call\n",
|
||||||
|
" func = eval(proc, env)\n",
|
||||||
|
" vals = [eval(arg, env) for arg in args]\n",
|
||||||
|
" return func(*vals)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "73750dec-a8e0-41fb-83ae-3c7740103659",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"For example:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 20,
|
||||||
|
"id": "fb398ac0-cd7f-45e2-9a8c-1ea15bc7b4e6",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"314.1592653589793\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"batch(\"\"\"\n",
|
||||||
|
"(begin \n",
|
||||||
|
" (define (circle-area r) (* pi (* r r)))\n",
|
||||||
|
" (circle-area (+ 5 5)))\"\"\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "1a2ccfcd-326b-44f0-b041-da657dc042a0",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"We now have a language with variables, conditionals, sequential execution, and procedures with recursive calls. That makes our language Turing-complete. If you are familiar with other languages, you might think that a `while` or `for` loop would be needed, but Scheme manages to do without these just fine. In Scheme you iterate by defining recursive functions. The Scheme report says \"Scheme demonstrates that a very small number of rules for forming expressions, with no restrictions on how they are composed, suffice to form a practical and efficient programming language.\" \n",
|
||||||
|
"\n",
|
||||||
|
"## How Small/Complete/Good/Fast is Lispy?\n",
|
||||||
|
" \n",
|
||||||
|
"In which we judge Lispy on several criteria:\n",
|
||||||
|
"- **Small**: Lispy is *very* small: about 120 lines or 4K of source code. (An earlier version was just 90 lines, but was perhaps a bit too terse.) The smallest version of my Scheme in Java, [Jscheme](http://norvig.com/jscheme.html) was 1664 lines and 57K of source. Jscheme was originally called SILK (Scheme in Fifty Kilobytes), but I only kept under that limit by counting bytecode rather than source code. Lispy does much better; I think it meets Alan Kay's 1972 [claim](http://gagne.homedns.org/~tgagne/contrib/EarlyHistoryST.html) that *you could define the \"most powerful language in the world\" in \"a page of code.\"* (if you use a small font). However, I think Alan would disagree, because he would count the Python compiler as part of the code, putting me <i>well</i> over a page.\n",
|
||||||
|
"- **Complete**: Lispy is not very complete compared to the [Scheme standard](https://standards.scheme.org/). Some major shortcomings:\n",
|
||||||
|
" - **Syntax**: Missing comments, quote and quasiquote notation, # literals, the derived\n",
|
||||||
|
" expression types (such as `cond` and `let`), and dotted list notation.\n",
|
||||||
|
" - **Semantics**: Missing `call/cc` and tail recursion. \n",
|
||||||
|
" - **Data Types**: Missing strings, characters, booleans, ports,\n",
|
||||||
|
" vectors, exact/inexact numbers. A Scheme list should actually be a custom data class, not a Python list.\n",
|
||||||
|
" - **Procedures**: Missing over 100 primitive procedures.\n",
|
||||||
|
" - **Error recovery**: Lispy does not attempt to detect,\n",
|
||||||
|
" reasonably report, or recover from errors. Lispy expects the\n",
|
||||||
|
" programmer to be perfect. \n",
|
||||||
|
"- **Good**: That's up to the readers to decide. I think that Lispy is good for my purpose of explaining Lisp interpreters. It is not a viable choice for serious software development.\n",
|
||||||
|
"- **Fast**: Lispy computes <tt>(factorial 100)</tt> in less than a millisecond. That's fast enough for me. <p>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 21,
|
||||||
|
"id": "5bcc6a7f-261b-4156-92d3-c771ecfcd109",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000\n",
|
||||||
|
"CPU times: user 395 μs, sys: 200 μs, total: 595 μs\n",
|
||||||
|
"Wall time: 521 μs\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"%%time\n",
|
||||||
|
"batch(\"\"\"\n",
|
||||||
|
"(begin \n",
|
||||||
|
" (define (factorial n) \n",
|
||||||
|
" (if (<= n 1) \n",
|
||||||
|
" 1 \n",
|
||||||
|
" (* n (factorial (- n 1)))))\n",
|
||||||
|
" (factorial 100))\"\"\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "802789ab-2f1c-4fb0-a79b-c7621a851e81",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## More Example Lisp Programs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 22,
|
||||||
|
"id": "f8728be6-2423-487f-a44a-49a50411d363",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"(count 3 4)\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"batch(\"\"\"\n",
|
||||||
|
"(list \n",
|
||||||
|
" (define (count item L) \n",
|
||||||
|
" (if (null? L)\n",
|
||||||
|
" 0\n",
|
||||||
|
" (+ (equal? item (first L)) (count item (rest L)))))\n",
|
||||||
|
" (count 0 (list 0 1 2 3 0 0))\n",
|
||||||
|
" (count (quote the) (quote (the more the merrier the bigger the better))))\"\"\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 23,
|
||||||
|
"id": "af58a444-c684-481c-a74b-1ad6bb49459b",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"(square compose repeat 10 81 65536 2.0)\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"batch(\"\"\"\n",
|
||||||
|
"(list\n",
|
||||||
|
" (define (square x) (* x x))\n",
|
||||||
|
" (define (compose f g) (lambda (x) (f (g x))))\n",
|
||||||
|
" (define (repeat f) (compose f f))\n",
|
||||||
|
" ((compose round sqrt) 101)\n",
|
||||||
|
" ((repeat square) 3)\n",
|
||||||
|
" ((repeat (repeat square)) 2)\n",
|
||||||
|
" ((repeat (repeat sqrt)) (pow 2 16)))\"\"\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 24,
|
||||||
|
"id": "5dba7073-33d3-4f39-a192-5e0ccdc42f8a",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"(1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765)\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"batch(\"\"\"\n",
|
||||||
|
"(begin\n",
|
||||||
|
" (define (fib n) \n",
|
||||||
|
" (if (< n 2) \n",
|
||||||
|
" 1 \n",
|
||||||
|
" (+ (fib (- n 1)) (fib (- n 2)))))\n",
|
||||||
|
" (define (range start stop)\n",
|
||||||
|
" (if (= start stop) \n",
|
||||||
|
" (quote ()) \n",
|
||||||
|
" (cons start (range (+ start 1) stop))))\n",
|
||||||
|
" (map fib (range 0 20)))\"\"\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "5f7fcfb8-ef93-4dfb-af8b-43030ab74eaa",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## True Story\n",
|
||||||
|
"\n",
|
||||||
|
"To back up the idea that it can be helpful to know how\n",
|
||||||
|
"interpreters work, here's a story. Way back in 1984 I was writing a\n",
|
||||||
|
"Ph.D. thesis. This was before LaTeX, before Microsoft Word for Windows–we used\n",
|
||||||
|
"[troff](https://en.wikipedia.org/wiki/Troff). Unfortunately, troff had no facility for forward references\n",
|
||||||
|
"to symbolic labels: I wanted to be able to write \"As we will see on\n",
|
||||||
|
"page @theorem-x\" and then write something like \"@(set theorem-x \\n%)\" in\n",
|
||||||
|
"the appropriate place (the troff register \\n% holds the page number). My\n",
|
||||||
|
"fellow grad student Tony DeRose felt the same need, and together we\n",
|
||||||
|
"sketched out a simple Lisp program that would handle this as a preprocessor. However,\n",
|
||||||
|
"it turned out that the Lisp we had at the time was good at reading\n",
|
||||||
|
"Lisp expressions, but slow at reading 100 KB of characters one character at a time.\n",
|
||||||
|
"\n",
|
||||||
|
"From there Tony and I split paths. He reasoned that the hard part was\n",
|
||||||
|
"the interpreter for expressions; he needed Lisp for that, but he knew\n",
|
||||||
|
"how to write a tiny C routine\n",
|
||||||
|
"for reading the characters one at a time, and how to link it into the Lisp\n",
|
||||||
|
"program. I didn't know how to do that linking, but I reasoned that writing an\n",
|
||||||
|
"interpreter for this trivial language (all it had was set variable,\n",
|
||||||
|
"fetch variable, and string concatenate) was easy, so I wrote an\n",
|
||||||
|
"interpreter in C. So, ironically, Tony wrote a Lisp program (with one small routine in C) because he was a\n",
|
||||||
|
"C programmer, and I wrote a C program (that implements a hand-coded mini-interpreter) because I was a Lisp programmer.\n",
|
||||||
|
"\n",
|
||||||
|
"In the end, we both got our theses done (<a href=\"http://www.eecs.berkeley.edu/Pubs/TechRpts/1985/6081.html\">Tony</a>, <a href=\"http://www.eecs.berkeley.edu/Pubs/TechRpts/1987/5995.html\">Peter</a>).\n",
|
||||||
|
"\n",
|
||||||
|
"<h2>Further Reading</h2>\n",
|
||||||
|
"\n",
|
||||||
|
"Years ago, I showed how to write a semi-practical near-complete Scheme interpreter (one in [Java](https://norvig.com/jscheme.html) and one in [Common Lisp](https://github.com/norvig/paip-lisp/blob/main/docs/chapter22.md)). I also have another page describing a <a href=\"http://norvig.com/lispy2.html\">more advanced version of Lispy</a>.\n",
|
||||||
|
" \n",
|
||||||
|
"To learn more about Scheme consult some of the fine books (by\n",
|
||||||
|
" <a\n",
|
||||||
|
" href=\"http://books.google.com/books?id=xyO-KLexVnMC&lpg=PP1&dq=scheme%20programming%20book&pg=PP1#v=onepage&q&f=false\">Friedman\n",
|
||||||
|
" and Fellesein</a>,\n",
|
||||||
|
" <a href=\"http://books.google.com/books?id=wftS4tj4XFMC&lpg=PA300&dq=scheme%20programming%20book&pg=PP1#v=onepage&q&f=false\">Dybvig</a>,\n",
|
||||||
|
" <a\n",
|
||||||
|
" href=\"http://books.google.com/books?id=81mFK8pqh5EC&lpg=PP1&dq=scheme%20programming%20book&pg=PP1#v=onepage&q&f=false\">Queinnec</a>,\n",
|
||||||
|
" <a href=\"http://www.eecs.berkeley.edu/~bh/ss-toc2.html\">Harvey and\n",
|
||||||
|
" Wright</a> or\n",
|
||||||
|
" <a href=\"https://www.researchgate.net/profile/Gerald-Sussman-2/publication/37597721_Structure_and_Interpretation_of_Computer_Programs_H_Abelson_GJ_Sussman_colaboracion_de_J_Sussman_prol_de_Alan_J_Perlis/links/53d141450cf220632f392bf7/Structure-and-Interpretation-of-Computer-Programs-H-Abelson-GJ-Sussman-colaboracion-de-J-Sussman-prol-de-Alan-J-Perlis.pdf\">Sussman and Abelson</a>),\n",
|
||||||
|
" videos (by <a\n",
|
||||||
|
" href=\"http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/\">Abelson\n",
|
||||||
|
" and Sussman</a>),\n",
|
||||||
|
" tutorials (by\n",
|
||||||
|
" <a\n",
|
||||||
|
" href=\"http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme.html\">Dorai</a>,\n",
|
||||||
|
" <a href=\"http://docs.racket-lang.org/quick/index.html\">PLT</a>, or\n",
|
||||||
|
" <a href=\"http://cs.gettysburg.edu/~tneller/cs341/scheme-intro/index.html\">Neller</a>),\n",
|
||||||
|
" or the\n",
|
||||||
|
" <a\n",
|
||||||
|
" href=\"http://www.schemers.org/Documents/Standards/R5RS/HTML\">reference\n",
|
||||||
|
" manual</a>.\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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.13.9"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 5
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ notebooks = {
|
|||||||
|
|
||||||
'Programming Examples': [
|
'Programming Examples': [
|
||||||
("AlphaCode Automated Programming", 2022, 'AlphaCode.ipynb', "Analysis of AlphaCode's automated solution to a coding problem"),
|
("AlphaCode Automated Programming", 2022, 'AlphaCode.ipynb', "Analysis of AlphaCode's automated solution to a coding problem"),
|
||||||
|
("Approximating Pi with a Fraction", 2026, 'RationalPi.ipynb', "Using continued fractions to find fractions (like 22/7) that are close to pi."),
|
||||||
('The Babylonian Number System', 2022, 'Babylonian%20digits.ipynb', 'Translating between Babylonian and traditional number systems.'),
|
('The Babylonian Number System', 2022, 'Babylonian%20digits.ipynb', 'Translating between Babylonian and traditional number systems.'),
|
||||||
("Beal's Conjecture Revisited", 2018, 'Beal.ipynb', "A search for counterexamples to Beal's Conjecture"),
|
("Beal's Conjecture Revisited", 2018, 'Beal.ipynb', "A search for counterexamples to Beal's Conjecture"),
|
||||||
('Bicycling Statistics', 2020, 'Bike-Stats.ipynb', 'Visualizing statistics about bike routes'),
|
('Bicycling Statistics', 2020, 'Bike-Stats.ipynb', 'Visualizing statistics about bike routes'),
|
||||||
@@ -57,7 +58,7 @@ notebooks = {
|
|||||||
('How to Count Things', 2020, 'How%20To%20Count%20Things.ipynb', 'Combinatorial math: how to count how many things there are, when there are a lot of them'),
|
('How to Count Things', 2020, 'How%20To%20Count%20Things.ipynb', 'Combinatorial math: how to count how many things there are, when there are a lot of them'),
|
||||||
('KenKen (Sudoku-like Puzzle)', 2021, 'KenKen.ipynb', 'A Sudoku-like puzzle, but with arithmetic.'),
|
('KenKen (Sudoku-like Puzzle)', 2021, 'KenKen.ipynb', 'A Sudoku-like puzzle, but with arithmetic.'),
|
||||||
('Number Bracelets Game', 2024, 'NumberBracelets.ipynb', 'A game involving numbered beads on a circular bracelet.'),
|
('Number Bracelets Game', 2024, 'NumberBracelets.ipynb', 'A game involving numbered beads on a circular bracelet.'),
|
||||||
('Project Euler #3: Largest prime factor', 'Euler3.ipynb', 2026, 'Find the largest prime factor of a number'),
|
('Project Euler #3: Largest prime factor', 2026, 'Euler3.ipynb', 'Find the largest prime factor of a number'),
|
||||||
('Pairing Socks', 2019, 'Socks.ipynb', 'What is the probability that you will be able to pair up socks as you randomly pull them out of the dryer?'),
|
('Pairing Socks', 2019, 'Socks.ipynb', 'What is the probability that you will be able to pair up socks as you randomly pull them out of the dryer?'),
|
||||||
('Sicherman Dice', 2018, 'Sicherman%20Dice.ipynb', 'Find a pair of dice that is like a regular pair of dice, only different'),
|
('Sicherman Dice', 2018, 'Sicherman%20Dice.ipynb', 'Find a pair of dice that is like a regular pair of dice, only different'),
|
||||||
("Sol Golomb's Rectangle Puzzle", 2014, 'Golomb-Puzzle.ipynb', 'A Puzzle involving placing rectangles of different sizes inside a square'),
|
("Sol Golomb's Rectangle Puzzle", 2014, 'Golomb-Puzzle.ipynb', 'A Puzzle involving placing rectangles of different sizes inside a square'),
|
||||||
@@ -111,6 +112,7 @@ notebooks = {
|
|||||||
'Computer Science Algorithms and Concepts': [
|
'Computer Science Algorithms and Concepts': [
|
||||||
('BASIC Interpreter', 2017, 'BASIC.ipynb', 'How to write an interpreter for the BASIC programming language'),
|
('BASIC Interpreter', 2017, 'BASIC.ipynb', 'How to write an interpreter for the BASIC programming language'),
|
||||||
('Convex Hull Problem', 2017, 'Convex%20Hull.ipynb', 'A classic Computer Science Algorithm'),
|
('Convex Hull Problem', 2017, 'Convex%20Hull.ipynb', 'A classic Computer Science Algorithm'),
|
||||||
|
('(How to Write a (Lisp) Interpreter (in Python))', 2026, 'lispy.ipynb', 'Tutorial on interpreters.'),
|
||||||
('Docstring Fixpoint Theory', 2023, 'DocstringFixpoint.ipynb', 'An approach to writing code and docstrings that go together.'),
|
('Docstring Fixpoint Theory', 2023, 'DocstringFixpoint.ipynb', 'An approach to writing code and docstrings that go together.'),
|
||||||
('Stable Matching Problem', 2020, 'StableMatching.ipynb', 'What is the best way to pair up two groups with each other, obeying preferences?'),
|
('Stable Matching Problem', 2020, 'StableMatching.ipynb', 'What is the best way to pair up two groups with each other, obeying preferences?'),
|
||||||
('Symbolic Algebra, Simplification, and Differentiation', 2017, 'Differentiation.ipynb', 'A computer algebra system, including symbolic differentiation'),
|
('Symbolic Algebra, Simplification, and Differentiation', 2017, 'Differentiation.ipynb', 'A computer algebra system, including symbolic differentiation'),
|
||||||
@@ -145,7 +147,7 @@ import re
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
current_year = 2026
|
current_year = 2026
|
||||||
new_year = current_year - 2 # What `find_newest` looks for
|
new_year = current_year - 1 # What `find_newest` looks for
|
||||||
|
|
||||||
def read_url(url: str) -> str:
|
def read_url(url: str) -> str:
|
||||||
"""Reads a file from the specified URL and returns its content as a string."""
|
"""Reads a file from the specified URL and returns its content as a string."""
|
||||||
@@ -192,20 +194,20 @@ def find_newest(notebooks, label='New', year=new_year) -> None:
|
|||||||
def format_category(category) -> str:
|
def format_category(category) -> str:
|
||||||
"""Make a table of multiple jupyter/ipython notebooks, under a header."""
|
"""Make a table of multiple jupyter/ipython notebooks, under a header."""
|
||||||
print(f'{len(notebooks[category]):2d} notebooks in {category}')
|
print(f'{len(notebooks[category]):2d} notebooks in {category}')
|
||||||
return table(('Run', 'Year', category),
|
return table(('Open', 'Year', category),
|
||||||
[format_notebook(*line) for line in notebooks[category]])
|
[format_notebook(*line) for line in notebooks[category]])
|
||||||
|
|
||||||
def format_notebook(title, year, url, comment=''):
|
def format_notebook(title, year, url, comment=''):
|
||||||
"""Make a markdown table entry for a jupyter/ipython notebook."""
|
"""Make a markdown table entry for a jupyter/ipython notebook."""
|
||||||
urlb = f'/blob/main/ipynb/{url}'
|
urlb = f'/blob/main/ipynb/{url}'
|
||||||
co = f'[C](https://colab.research.google.com/github/norvig/pytudes{urlb})'
|
co = f'[co](https://colab.research.google.com/github/norvig/pytudes{urlb})'
|
||||||
gh = f'[G](ipynb/{url})'
|
gh = f'[G](ipynb/{url})'
|
||||||
dn = f'[D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2F{url})'
|
dn = f'[D](https://beta.deepnote.org/launch?template=python_3.6&url=https%3A%2F%2Fgithub.com%2Fnorvig%2Fpytudes%2Fblob%2Fmain%2Fipynb%2F{url})'
|
||||||
my = f'[M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2F{url})'
|
my = f'[M](https://mybinder.org/v2/gh/norvig/pytudes/main?filepath=ipynb%2F{url})'
|
||||||
nb = f'[N](https://nbviewer.jupyter.org/github/norvig/pytudes{urlb})'
|
nb = f'[nb](https://nbviewer.jupyter.org/github/norvig/pytudes{urlb})'
|
||||||
sm = f'[S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes{urlb})'
|
sm = f'[S](https://studiolab.sagemaker.aws/import/github/norvig/pytudes{urlb})'
|
||||||
ti = f'<a href="{gh[4:-1]}" title="{comment}">{title}</a>'
|
ti = f'<a href="{gh[4:-1]}" title="{comment}">{title}</a>'
|
||||||
return f'| {co} {dn} {my} {nb} {sm} | {year} | {ti} |'
|
return f'| {co} {nb} | {year} | {ti} |'
|
||||||
|
|
||||||
def format_pythons() -> str:
|
def format_pythons() -> str:
|
||||||
"""Make a table of multiple python programs."""
|
"""Make a table of multiple python programs."""
|
||||||
@@ -237,12 +239,9 @@ To continue the musical analogy, some people think of programming like [Spotify]
|
|||||||
|
|
||||||
# Index of Jupyter (IPython) Notebooks
|
# Index of Jupyter (IPython) Notebooks
|
||||||
|
|
||||||
For each notebook you can hover on the title to see a description, or click the title to view on github, or click one of the letters in the left column to launch the notebook on
|
For each notebook you can hover on the title to see a description, or click the title to view on github, or click one of the letters in the left column to open the notebook on
|
||||||
[**C**olab](https://colab.research.google.com),
|
[**co**lab](https://colab.research.google.com) or
|
||||||
[**D**eepnote](https://deepnote.com),
|
[**nb**viewer](https://nbviewer.jupyter.org/).
|
||||||
[**M**ybinder](https://mybinder.org),
|
|
||||||
[**S**agemaker](https://studiolab.sagemaker.aws/), or
|
|
||||||
[**N**BViewer](https://nbviewer.jupyter.org/).
|
|
||||||
|
|
||||||
{format_notebooks()}
|
{format_notebooks()}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user