Awesome
<div align="right" style="text-align:right"><i>Peter Norvig <br><a href="https://github.com/norvig/pytudes/blob/main/LICENSE">MIT License</a><br>2015-2022</i></div>pytudes
"An étude (a French word meaning study) is an instrumental musical composition, usually short, of considerable difficulty, and designed to provide practice material for perfecting a particular musical skill." — Wikipedia
This project contains pytudes—Python programs, usually short, for perfecting particular programming skills.
Who is this for?
To continue the musical analogy, some people think of programming like Spotify: they want to know how to install the app, find a good playlist, and hit the "play" button; after that they don't want to think about it. There are plenty of other tutorials that will tell you how to do the equivalent of that for various programming tasks—this one won't help. But if you think of programming like playing the piano—a craft that can take years to perfect—then I hope this collection can help.
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 Colab, Deepnote, Mybinder, Sagemaker, or NBViewer.
Run | Year | New |
---|---|---|
C D M N S | <u>2024</u> | <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 D M N S | <u>2024</u> | <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 D M N S | <u>2024</u> | <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 D M N S | <u>2024</u> | <a href="ipynb/NumberBracelets.ipynb" title="A game involving numbered beads on a circular bracelet.">Number Bracelets Game</a> |
C D M N S | <u>2024</u> | <a href="ipynb/Overtime.ipynb" title="In American Football, which team has the advantage in overtime?">Overtime in American Football</a> |
C D M N S | <u>2024</u> | <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 D M N S | <u>2024</u> | <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 D M N S | 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 D M N S | 2023 | <a href="ipynb/DocstringFixpoint.ipynb" title="An approach to writing code and docstrings that go together.">Docstring Fixpoint Theory</a> |
C D M N S | 2023 | <a href="ipynb/OneLetterOff.ipynb" title="Word game; use of a large language model to generate clues.">One Letter Off</a> |
C D M N S | 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> |
Run | Year | Programming Examples |
---|---|---|
C D M N S | 2022 | <a href="ipynb/AlphaCode.ipynb" title="Analysis of AlphaCode's automated solution to a coding problem">AlphaCode Automated Programming</a> |
C D M N S | 2022 | <a href="ipynb/Babylonian%20digits.ipynb" title="Translating between Babylonian and traditional number systems.">The Babylonian Number System</a> |
C D M N S | 2018 | <a href="ipynb/Beal.ipynb" title="A search for counterexamples to Beal's Conjecture">Beal's Conjecture Revisited</a> |
C D M N S | 2020 | <a href="ipynb/Bike-Stats.ipynb" title="Visualizing statistics about bike routes">Bicycling Statistics</a> |
C D M N S | 2018 | <a href="ipynb/Cant-Stop.ipynb" title="Optimal play in a dice board game">Can't Stop</a> |
C D M N S | 2019 | <a href="ipynb/Sierpinski.ipynb" title="A surprising appearance of the Sierpinski triangle in a random walk">Chaos with Triangles</a> |
C D M N S | 2017 | <a href="ipynb/Life.ipynb" title="The cellular automata zero-player game">Conway's Game of Life</a> |
C D M N S | 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 D M N S | <u>2024</u> | <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 D M N S | 2021 | <a href="ipynb/Konane.ipynb" title="Solving the game of Konane (Hawaiian checkers).">Mel's Konane Board</a> |
C D M N S | 2020 | <a href="ipynb/PhotoFocalLengths.ipynb" title="Generate charts of what focal lengths were used on a photo trip">Photo Focal Lengths</a> |
C D M N S | 2018 | <a href="ipynb/Pickleball.ipynb" title="Scheduling a doubles tournament fairly and efficiently">Pickleball Tournament</a> |
C D M N S | 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 D M N S | 2022 | <a href="ipynb/Menu.ipynb" title="Efficiently Selecting Names from a Menu, by typing characters and arrows">Selecting Names from a Menu</a> |
C D M N S | 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 |
---|---|---|
C D M N S | <u>2024</u> | <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 D M N S | 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 D M N S | 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 D M N S | 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 D M N S | 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 D M N S | 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 D M N S | 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 D M N S | 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 D M N S | 2022 | <a href="ipynb/AdventUtils.ipynb" title="Utility functions for Advent of Code puzzles">Advent of Code Utilities</a> |
Run | Year | Probability and Uncertainty |
---|---|---|
C D M N S | 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 D M N S | 2018 | <a href="ipynb/Probability.ipynb" title="Code and examples of the basic principles of Probability Theory">A Concrete Introduction to Probability</a> |
C D M N S | 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 D M N S | 2020 | <a href="ipynb/ProbabilitySimulation.ipynb" title="When the sample space is too complex, simulations can estimate probabilities">Estimating Probabilities with Simulations</a> |
C D M N S | 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 D M N S | 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 D M N S | 2020 | <a href="ipynb/Dice%20Baseball.ipynb" title="Simulating baseball games">Dice Baseball</a> |
C D M N S | 2018 | <a href="ipynb/Economics.ipynb" title="A simulation of a simple economic game">Economics Simulation</a> |
C D M N S | <u>2024</u> | <a href="ipynb/Overtime.ipynb" title="In American Football, which team has the advantage in overtime?">Overtime in American Football</a> |
C D M N S | 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 D M N S | 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 D M N S | 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 |
---|---|---|
C D M N S | <u>2024</u> | <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 D M N S | 2014 | <a href="ipynb/Cryptarithmetic.ipynb" title="Substitute digits for letters and make NUM + BER = PLAY">Cryptarithmetic</a> |
C D M N S | 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 D M N S | 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 D M N S | 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 D M N S | 2021 | <a href="ipynb/KenKen.ipynb" title="A Sudoku-like puzzle, but with arithmetic.">KenKen (Sudoku-like Puzzle)</a> |
C D M N S | <u>2024</u> | <a href="ipynb/NumberBracelets.ipynb" title="A game involving numbered beads on a circular bracelet.">Number Bracelets Game</a> |
C D M N S | 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 D M N S | 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 D M N S | 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 D M N S | <u>2024</u> | <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 D M N S | 2021 | <a href="ipynb/StarBattle.ipynb" title="Fill-in-the-grid puzzle similar to Sudoku">Star Battle (Sudoku-like Puzzle)</a> |
C D M N S | 2006 | <a href="ipynb/Sudoku.ipynb" title="Classic fill-in-the-grid puzzle">Sudoku</a> |
C D M N S | 2021 | <a href="ipynb/SudokuJava.ipynb" title="A version of the Sudoku solver using parallel threads and other optimizations">Sudoku: 100,000 puzzles/second in Java</a> |
C D M N S | 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 D M N S | 2020 | <a href="ipynb/Cheryl.ipynb" title="Solving the *Cheryl's Birthday* logic puzzle">When is Cheryl's Birthday?</a> |
C D M N S | 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 D M N S | <u>2024</u> | <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 D M N S | 2015 | <a href="ipynb/xkcd1313.ipynb" title="Find the smallest regular expression; inspired by Randall Munroe">xkcd 1313: Regex Golf</a> |
C D M N S | 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 |
---|---|---|
C D M N S | 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 D M N S | 2020 | <a href="ipynb/ElementSpelling.ipynb" title="Spelling words using the chemical element symbols, like CoIn">Chemical Element Spelling</a> |
C D M N S | 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 D M N S | 2017 | <a href="ipynb/Gesture%20Typing.ipynb" title="What word has the longest path on a gesture-typing smartphone keyboard?">Gesture Typing</a> |
C D M N S | 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 D M N S | 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 D M N S | 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 D M N S | 2023 | <a href="ipynb/OneLetterOff.ipynb" title="Word game; use of a large language model to generate clues.">One Letter Off</a> |
C D M N S | 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 D M N S | 2020 | <a href="ipynb/SpellingBee.ipynb" title="Find the highest-scoring board for the NY Times Spelling Bee puzzle">Spelling Bee</a> |
C D M N S | 2017 | <a href="ipynb/PropositionalLogic.ipynb" title="Automatically convert informal English sentences into formal Propositional Logic">Translating English into Propositional Logic</a> |
C D M N S | 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 D M N S | 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 D M N S | 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 D M N S | 2020 | <a href="ipynb/Portmantout.ipynb" title="Find a word that squishes together a bunch of words">World's Shortest Portmantout Word</a> |
C D M N S | 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) |
---|---|---|
C D M N S | 2022 | <a href="ipynb/Anigrams.ipynb" title="Finding the longest chain of anagrams that each add one letter">Anigrams: Word Chains</a> |
C D M N S | 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 D M N S | 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 D M N S | 2021 | <a href="ipynb/CrossProduct.ipynb" title="A puzzle where digits fill a table, subject to constraints on their products">CrossProduct</a> |
C D M N S | 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 D M N S | 2019 | <a href="ipynb/RiddlerLottery.ipynb" title="Can you find what lottery number tickets these five friends picked?">Lottery</a> |
C D M N S | 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 D M N S | 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 D M N S | 2018 | <a href="ipynb/Orderable%20Cards.ipynb" title="Can you get your hand of cards into a nice order with just one move?">Properly Ordered Card Hands</a> |
C D M N S | 2021 | <a href="ipynb/RaceTrack.ipynb" title="Race virtual cars around a circular track defined on a grid of points.">Race Track</a> |
C D M N S | 2021 | <a href="ipynb/SplitStates.ipynb" title="Split the US states into two near-halves by area.">Split the States</a> |
C D M N S | 2020 | <a href="ipynb/TourDe538.ipynb" title="Solve a puzzle involving the best pace for a bicycle race.">Tour de 538</a> |
C D M N S | 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 D M N S | 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 |
---|---|---|
C D M N S | 2017 | <a href="ipynb/BASIC.ipynb" title="How to write an interpreter for the BASIC programming language">BASIC Interpreter</a> |
C D M N S | 2017 | <a href="ipynb/Convex%20Hull.ipynb" title="A classic Computer Science Algorithm">Convex Hull Problem</a> |
C D M N S | 2023 | <a href="ipynb/DocstringFixpoint.ipynb" title="An approach to writing code and docstrings that go together.">Docstring Fixpoint Theory</a> |
C D M N S | 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 D M N S | 2017 | <a href="ipynb/Differentiation.ipynb" title="A computer algebra system that, including symbolic differentiation">Symbolic Algebra, Simplification, and Differentiation</a> |
C D M N S | 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 D M N S | 2018 | <a href="ipynb/TSP.ipynb" title="Another of the classics">Traveling Salesperson Problem</a> |
Index of Python Files
File | Description | Documentation |
---|---|---|
beal.py | Search for counterexamples to Beal's Conjecture | documentation |
docex.py | An obsolete framework for running unit tests, similar to doctest | |
ibol.py | An Exercise in Species Barcoding | documentation |
lettercount.py | Convert Google Ngram Counts to Letter Counts | documentation |
lis.py | Lisp Interpreter written in Python | documentation |
lispy.py | Even Better Lisp Interpreter written in Python | documentation |
lispytest.py | Tests for Lisp Interpreters | |
pal.py | Find long palindromes | documentation |
pal2.py | Find longer palindromes | documentation |
pal3.py | Find even longer palindromes | documentation |
pytudes.py | Pre-process text to generate this README.md file. | |
py2html.py | Pretty-printer to format Python files as html | |
SET.py | Analyze the card game SET | documentation |
spell.py | Spelling corrector | documentation |
sudoku.py | Program to solve sudoku puzzles | documentation |
testaccum.py | Tests for my failed Python accumulation display proposal | documentation |
yaptu.py | Yet Another Python Templating Utility |
Etudes for Programmers
I got the idea for the "etudes" part of the name from this 1978 book by Charles Wetherell that was very influential to me when I was first learning to program. I still have my copy.