"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.
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.
Click a title to see a notebook on GitHub, or click the
icon next to it to run it in Colab
.
Hover over a title to see the full name, year, and a description.
- Approximating Pi with a Fraction
· Did you solve it? R y clvr ngh t rd ths sntnc?
· (How to Write a (Lisp) Interpreter (in Python))
· Integer Palindromes
· Largest prime factor
· Provably Shortest Portmantout Word
· Truncatable Primes
- Project Euler:
by me
· by Claude Fable
· by Claude Opus
· by Kimi
- Coding with AI:
AlphaCode automated programming
· The languages of English, math, and programming
- Language models:
Effectiveness of language models
· How to do things with words
· One letter off
- See also: Project Euler by LLMs · Advent of Code 2025 by LLMs · LLMs and Cheryl's Birthday · Integer palindromes (human vs. LLM) · Provably shortest portmantout (found by Claude)
- Fundamentals:
A concrete introduction
· Paradoxes and the reasonable person principle
· Estimating with simulations
· How to count things
- Games of chance:
Poker hand ranking
· The unfinished game of Risk
· The Devil and the coin flip
· The diamond game
- Sports:
Who will win the NBA title?
· Overtime in American football
· Dice baseball
- Simulations:
Economics simulation
· Pairing socks
· Cluster sizes in paint by numbers
🎄 Advent of Code (Problems from adventofcode.com)
- By year:
2016
· 2017
· 2018
· 2020
· 2021
· 2022
· 2023
· 2024
· 2025
- Extras:
2025: solved by AI LLMs
· Utility functions
🧮 Project Euler (Problems from projecteuler.net)
- Problems #1–100:
by a human
· by Claude Fable
· by Claude Opus
· by Kimi
- For beginners:
Largest prime factor (#3)
- Cheryl's Birthday:
When is Cheryl's birthday?
· When Cheryl met Eve
· LLMs and theory of mind
- Arithmetic puzzles:
Four 4s, five 5s, and countdowns
· Cryptarithmetic
· Square sum chains
· Number bracelets
· Sicherman dice
- Number theory:
Approximating pi with a fraction
· Truncatable primes
· Stubborn number endings
· The Babylonian number system
- Famous conjectures:
Beal's conjecture revisited
· Euler's sum of powers conjecture
- Sudoku:
in Python
· in Java: 400,000 puzzles/second
- Sudoku-like puzzles:
KenKen
· Star Battle
· Sol Golomb's rectangle puzzle
- Board games:
Can't Stop
· Mel's Konane board
- Wordle:
Wordle, Evil Wordle, Antiwordle, and Jotto
· Winning Wordle
- Palindromes:
World's longest palindrome
· Integer palindromes
- Portmantout:
Portmantout words
· Provably shortest
- Word games:
Boggle / inverse Boggle
· Ghost
· Scrabble
· Spelling Bee
· Gesture typing
- Wordplay:
Chemical element spelling
· Equilength numbers: FOUR = 4
· Let's code about bike locks
· R y clvr ngh t rd ths?
- The Riddler (FiveThirtyEight):
Anigrams
· Battle Royale
· Climbing wall
· CrossProduct
· Flipping cards
· Lottery
· The Night King
· Misanthropic neighbors
· Organized card hands
· Race track
· Split the states
· Tour de 538
· Weighing twelve balls
· War
- xkcd:
Regex golf (#1313)
· Regex golf, part 2
· Name dominoes (#1970)
- Interpreters and languages:
Lisp interpreter
· BASIC interpreter
· Symbolic algebra and differentiation
· Snobol: bad grade, good experience
- Classic algorithms:
Traveling salesperson
· Convex hull
· Stable matching
· Generating and solving mazes
- Software craft:
Docstring fixpoint theory
· Translating English into propositional logic
· Selecting names from a menu
· Scheduling a pickleball tournament
- Data visualization:
Bicycling statistics
· Photo focal lengths
· Tracking polls: electoral votes
- Emergent patterns:
Conway's Game of Life
· Chaos with triangles
| 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 |
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, but it is now easier to find a pdf than a hard copy.
Here's what some people are saying about pytudes:
- "What I find interesting is how Peter builds bottom-up solutions using low-level utilities... Reading his code is educational." - Jeremey Howard, co-founder of fast.ai and chief scientist at Kaggle
- "Everything I see from Peter Norvig is just always so incredibly well written and coded." — Jonathan, Hacker News
- "Peter Norvig is my go to recommendation when someone is interested in becoming better at solving day to day problems ... I feel his skill of dividing a problem into small pieces and expressing them in code in a natural way is unparalleled." — mikevin, Hacker News
- "I've never seen Peter Norvig choose anything but the most elegant and perfect data model for the problem at hand." — spoonjim, Hacker News
- "I just find Norvig's style of "functional Python" lovely in its own way (with noted disregard of Pep8 and other "best practices")" —raverbashing, Hacker News
- "You should check out Norvig's design of computer programs course on Udacity where he uses these kinds of puzzle programs to teach programming design concepts. It is a hard but really rewarding course. — nafizh, HN ACademy
- "Often enough I would think of something [a possible improvement[, but if you worked it out in detail there was some less-obvious reason the code was the way it was... All the code is pretty short, and it's not really 'production code', but it's enough to be an education in craftsmanship at every level."
- [What code samples should programmers read?] "Anything else implemented by Norvig, he's one of the best programmers that I've had the pleasure of reading code from." - jacquesm on Hacker News
- "Everything I see from Peter Norvig is just always so incredibly well written and coded. Every year looking at his solutions for advent of code [0] brings just so much learnings. Strongly recommend. - jyepin Hacker News
- "I feel his skill of dividing a problem into small pieces and expressing them in code in a natural way is unparalleled." - mikevin Hacker News
