Python programs, usually short, of considerable difficulty, to perfect particular skills.

Overview
Peter Norvig
MIT License
2015-2020

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:

  • Click on c to run the notebook on Colab
  • Click on d to run the notebook on DeepNote
  • Click on m to run the notebook on MyBinder
  • Click on n to view the notebook on NBViewer
  • Click on the title to view the notebook on github.
  • Hover over the title to view a description.
Run Year Recent (2021)
c d m n 2021 Advent of Code 2021
c d m n 2021 Mel's Konane Board
c d m n 2021 KenKen (Sudoku-like Puzzle)
c d m n 2021 Star Battle (Sudoku-like Puzzle)
c d m n 2021 Sudoku: 100,000 puzzles/second in Java
c d m n 2021 CrossProduct
c d m n 2021 Split the States
Run Year Programming Examples
c d m n 2021 Advent of Code 2021
c d m n 2020 Advent of Code 2020
c d m n 2018 Advent of Code 2018
c d m n 2017 Advent of Code 2017
c d m n 2016 Advent of Code 2016
c d m n 2018 Beal's Conjecture Revisited
c d m n 2020 Bicycling Statistics
c d m n 2018 Can't Stop
c d m n 2019 Chaos with Triangles
c d m n 2017 Conway's Game of Life
c d m n 2020 Generating and Solving Mazes
c d m n 2021 Mel's Konane Board
c d m n 2020 Photo Focal Lengths
c d m n 2018 Pickleball Tournament
c d m n 2017 Project Euler Utilities
c d m n 2020 Tracking Trump: Electoral Votes
Run Year Logic and Number Puzzles
c d m n 2014 Cryptarithmetic
c d m n 2018 Euler's Sum of Powers Conjecture
c d m n 2020 Four 4s, Five 5s, and Countdowns
c d m n 2021 KenKen (Sudoku-like Puzzle)
c d m n 2019 Pairing Socks
c d m n 2018 Sicherman Dice
c d m n 2014 Sol Golomb's Rectangle Puzzle
c d m n 2021 Star Battle (Sudoku-like Puzzle)
c d m n 2006 Sudoku
c d m n 2021 Sudoku: 100,000 puzzles/second in Java
c d m n 2020 Square Sum Puzzle
c d m n 2020 When is Cheryl's Birthday?
c d m n 2015 When Cheryl Met Eve: A Birthday Story
c d m n 2015 xkcd 1313: Regex Golf
c d m n 2015 xkcd 1313: Regex Golf (Part 2: Infinite Problems)
Run Year Word Puzzles
c d m n 2020 Boggle / Inverse Boggle
c d m n 2020 Chemical Element Spelling
c d m n 2020 Equilength Numbers: FOUR = 4
c d m n 2017 Gesture Typing
c d m n 2017 Ghost: A Word game
c d m n 2018 How to Do Things with Words: NLP in Python
c d m n 2020 Jotto: A Word Guessing Game
c d m n 2015 Let's Code About Bike Locks
c d m n 2017 Scrabble: Refactoring a Crossword Game Program
c d m n 2020 Spelling Bee
c d m n 2017 Translating English into Propositional Logic
c d m n 2017 World's Longest Palindrome
c d m n 2020 World's Shortest Portmantout Word
c d m n 2018 xkcd 1970: Name Dominoes
Run Year Probability and Uncertainty
c d m n 2018 A Concrete Introduction to Probability
c d m n 2016 Probability, Paradox, and the Reasonable Person Principle
c d m n 2020 Estimating Probabilities with Simulations
c d m n 2019 The Devil and the Coin Flip Game
c d m n 2020 Dice Baseball
c d m n 2018 Economics Simulation
c d m n 2012 Poker Hand Ranking
c d m n 2020 The Unfinished Game .... of Risk
c d m n 2019 WWW: Who Will Win (NBA Title)?
Run Year The Riddler (from 538)
c d m n 2017 Battle Royale
c d m n 2021 CrossProduct
c d m n 2020 Flipping Cards; A Guessing Game
c d m n 2019 Lottery
c d m n 2019 How Many Soldiers to Beat the Night King?
c d m n 2017 Misanthropic Neighbors
c d m n 2018 Properly Ordered Card Hands
c d m n 2021 Split the States
c d m n 2020 Tour de 538
c d m n 2020 Weighing Twelve Balls
c d m n 2020 War. What is it Good For?
Run Year Computer Science Algorithms and Concepts
c d m n 2017 BASIC Interpreter
c d m n 2017 Convex Hull Problem
c d m n 2020 How to Count Things
c d m n 2020 Stable Matching Problem
c d m n 2017 Symbolic Algebra, Simplification, and Differentiation
c d m n 2017 Snobol: Bad Grade, Good Experience
c d m n 2018 Traveling Salesperson Problem

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.

Comments
  • Input now downloads files from Github

    Input now downloads files from Github

    Previously interested programmers who only downloaded the iPython notebook had to download your specific input data separately (or download their own inputs). With this fix the input files are downloaded from your Github repository as soon as Input(day) is called.

    opened by rmeertens 6
  • Python3 compatibility How to Do Things with Words.ipynb

    Python3 compatibility How to Do Things with Words.ipynb

    Hello,

    I'm trying to use 'How to Do Things with Words' notebook but...


    NameError Traceback (most recent call last) in () ----> 1 TEXT = file('big.txt').read() 2 len(TEXT)

    NameError: name 'file' is not defined

    • I think this should be replaced to use open() instead of file().

    • I was able to use 'big.txt' downloading from https://norvig.com/big.txt .Not sure if its the same.

    I'll upload a PR to make it py3 compatible.

    opened by pathcl 4
  • missing data/advent2018 input folder

    missing data/advent2018 input folder

    Hi, missing input folder data/advent2018 in repository Alessio

    input1 = Input(1, int)

    sum(input1)

    FileNotFoundError Traceback (most recent call last) in ----> 1 input1 = Input(1, int) 2 3 sum(input1)

    in Input(day, line_parser, file_template) 18 def Input(day, line_parser=str.strip, file_template='data/advent2018/input{}.txt'): 19 "For this day's input file, return a tuple of each line parsed by line_parser." ---> 20 return mapt(line_parser, open(file_template.format(day))) 21 22 def integers(text):

    FileNotFoundError: [Errno 2] No such file or directory: 'data/advent2018/input1.txt'

    opened by alessiomargan 2
  • Loading function for loading files

    Loading function for loading files "count_1w.txt" is not working

    Hi,

    This function is always throwing an error.

    def load_counts(filename, sep='\t'): """Return a Counter initialized from key-value pairs, one on each line of filename.""" C = Counter() for line in open(filename): key, count = line.split(sep) C[key] = int(count) return C

    Sometimes it is throwing an error of this type:- Error is in line --> 168 C[key].append(int(count))

    and error is--> TypeError: unhashable type: 'list'

    And sometimes:- --> 167 key, count = line.split(sep)

    ValueError: not enough values to unpack (expected 2, got 1)

    I can't find the reason.Please help.I am using Python3 and have edited everything related to Python3 in this program.Please let me know the reason of above errors.

    opened by pallavi-xtage 2
  • Split error while input string contained whitespace in tokenize function under lis.py

    Split error while input string contained whitespace in tokenize function under lis.py

    for example , just input "hello wolrd" after call repl()

    "hello world" will be splitted to two tokens like ("hello) and (world"). it should be treated as one single string expression, not two tokens, otherwise "hello will be thought as an operator, but it can not be found from environment.

    Below is my test log:

    lis.py> "hello world" Traceback (most recent call last): File "", line 1, in File "/home/klose/Documents/programming/python/intepreter/lis.py", line 98, in repl val = eval(parse(raw_input(prompt))) File "/home/klose/Documents/programming/python/intepreter/lis.py", line 123, in eval return env.find(x)[x] File "/home/klose/Documents/programming/python/intepreter/lis.py", line 89, in find return self if (var in self) else self.outer.find(var) AttributeError: 'NoneType' object has no attribute 'find'

    opened by klose911 2
  • Added all jupyter notebooks to Travis

    Added all jupyter notebooks to Travis

    Last time I only added the BASIC and Cheryl notebook to the notebooks that are evaluated in Travis, now added all notebooks in the ipynb folder...

    While testing on my local computer some notebooks did not fully run. If this is appreciated I might have some time to look into the possible issues next week. Let me know if this is something you want!

    opened by rmeertens 2
  • advent 2017 day 5 functions mutate the list

    advent 2017 day 5 functions mutate the list

    I think it would be good to create a copy of M within the run and run2 functions to avoid mutating the list that is passed in - it worked out fine since you created the input each time, but it would have gone wrong if you had only created it once.

    opened by ClementSreeves 2
  • "Advent of Code 2021" is actually "Advent of Code 2020"

    @norvig, you have Advent of Code 2020 notebooks and you have Advent of Code 2021 notebooks (if you believe the hyperlink text, anyway), but following the links to the mentioned notebooks reveals that everything leads to the one and only Advent of Code 2020.

    There aren't any real Advent of Code 2021 notebooks, are there, Peter? Is this an early April Fools' Day prank maybe?

    opened by PedanticHacker 1
  • Update Probability.ipynb to clarify

    Update Probability.ipynb to clarify "Event".

    From the linked Wikipedia-article: "In probability theory, an event is a set of outcomes of an experiment (a subset of the sample space) to which a probability is assigned."

    I believe this formulation is clearer than previous.

    opened by ocyj 1
  • Typo: 4^9 not 9^4

    Typo: 4^9 not 9^4

    Perhaps, there's a typo in the number of possibilities here: https://github.com/norvig/pytudes/blame/master/ipynb/Countdown.ipynb#L58

    It might be meant to be the other way around 4^9 = 262,144 instead of 9^4.

    image

    opened by iamaziz 1
  • add random population member to percentile plot

    add random population member to percentile plot

    Thought it would be interesting to not only have a population perspective but also an individual one. MR adds the wealth of a random population member as it varies through time to the percentile plot.

    opened by howtodowtle 1
  • A Chaos Game with Triangles - Improvements with Transparency and Oversampling

    A Chaos Game with Triangles - Improvements with Transparency and Oversampling

    Hello,

    It is possible to significantly and cheaply improve the rendering of the figures of the A Chaos Game with Triangles notebook by using transparency, smaller marker size and a some oversampling:

    def show_walk(vertexes, N=5000):
        "Walk halfway towards a random vertex for N points; show reults."
        Xs, Ys = transpose(random_walk(vertexes, N))
        Xv, Yv = transpose(vertexes)
        plt.plot(Xs, Ys, 'r.', alpha=0.5, markersize=1)
        plt.plot(Xv, Yv, 'bs', clip_on=False)
        plt.gca().set_aspect('equal')
        plt.gcf().set_size_inches(9, 9)
        plt.axis('off')
        plt.show()
    

    image image

    image image

    opened by KelSolaar 0
  • Wordle: Adjust expected_wins for bin size

    Wordle: Adjust expected_wins for bin size

    Let M = 2315 (total number of possible answers) and n = the size of bin for pattern n.

    In the original version

    P(Guess in 2) = 1/M * Sum(Prob(Guess in 2 | Pattern))
                  = 1/M * Sum(1 / n) 
    

    But, by Total Probability, I believe the formula should be:

    P(Guess in 2) = Sum(Prob(Guess in 2 | Pattern) * P(Pattern))
                  = Sum(1 / n * n / M)
                  = 1 / M * Sum(1)
    

    The result is counter-intuitive to me, but the probability of a guess in 2 only depends on the number of (non-empty) bins/partitions that are created from a guess.

    Credit to @fitzme for help verifying the math.

    opened by jobevers 0
  • Chaos with triangles

    Chaos with triangles

    Hi,

    I have extended your & John Cook's work on this topic using fractional steps and wanted to share that. There is a 'chaotic' puzzle to this when the fractional step is -1 and could be an interesting topic in itself:

    https://github.com/cdragun/python-progs/blob/master/Sierpinski.ipynb

    Regards, Chandra

    opened by cdragun 1
Owner
Peter Norvig
Author, Programmer, Teacher, Research Director at Google
Peter Norvig
Python script to commit to your github for a perfect commit streak. This is purely for education purposes, please don't use this script to do bad stuff.

Daily-Git-Commit Commit to repo every day for the perfect commit streak Requirments pip install -r requirements.txt Setup Download this repository. Cr

JareBear 34 Dec 14, 2022
Python Projects is an Open Source to enhance your python skills

Welcome! ???? Python Project is Open Source to enhance your python skills. You're free to contribute. ?? You just need to give us your scripts written

Tristán 6 Nov 28, 2022
Python wrapper to different clients to determine how a particular term is used.

Python wrapper to different clients to determine how a particular term is used.

Chris Mungall 3 Oct 24, 2022
Use this function to get list of routes for particular journey

route-planner Functions api_processing Use this function to get list of routes for particular journey. Function has three parameters: Origin Destinati

null 2 Nov 28, 2021
PyDy, short for Python Dynamics, is a tool kit written in the Python

PyDy, short for Python Dynamics, is a tool kit written in the Python programming language that utilizes an array of scientific programs to enable the study of multibody dynamics. The goal is to have a modular framework and eventually a physics abstraction layer which utilizes a variety of backends that can provide the user with their desired workflow

PyDy 307 Jan 1, 2023
Short, introductory guide for the Python programming language

100 Page Python Intro This book is a short, introductory guide for the Python programming language.

Sundeep Agarwal 185 Dec 26, 2022
List of short Codeforces problems with a statement of 1000 characters or less. Python script and data files included.

Shortest problems on Codeforces List of Codeforces problems with a short problem statement of 1000 characters or less. Sorted for each rating level. B

null 32 Dec 24, 2022
Py4J enables Python programs to dynamically access arbitrary Java objects

Py4J Py4J enables Python programs running in a Python interpreter to dynamically access Java objects in a Java Virtual Machine. Methods are called as

Barthelemy Dagenais 1k Jan 2, 2023
A code base for python programs the goal is to integrate all the useful and essential functions

Base Dev EN This GitHub will be available in French and English FR Ce GitHub sera disponible en français et en anglais Author License Screen EN ???? D

Pikatsuto 1 Mar 7, 2022
Hypothesis strategies for generating Python programs, something like CSmith

hypothesmith Hypothesis strategies for generating Python programs, something like CSmith. This is definitely pre-alpha, but if you want to play with i

Zac Hatfield-Dodds 73 Dec 14, 2022
A series of basic programs written in Python

Primeros programas en Python Una serie de programas básicos escritos en Python

Madirex 1 Feb 15, 2022
Repo created for the purpose of adding any kind of programs and projects

Programs and Project Repository A repository for adding programs and projects of any kind starting from beginners level to expert ones Contributing to

Unicorn Dev Community 3 Nov 2, 2022
A platform for developers 👩‍💻 who wants to share their programs and projects.

Fest-Practice-2021 This project is excluded from Hacktoberfest 2021. Please use this as a testing repo/project. A platform for developers ??‍?? who wa

Mayank Choudhary 40 Nov 7, 2022
Repo created for the purpose of adding any kind of programs and projects

Programs and Project Repository A repository for adding programs and projects of any kind starting from beginners level to expert ones Contributing to

Unicorn Dev Community 3 Nov 2, 2022
Dotfiles & list of programs

dotfiles & list of programs So I wanted to just backup my most used files. I have a bad habit, sometimes I get tired of a distro and do a wipe and sta

null 2 Sep 4, 2022
Some shitty programs just to brush up on my understanding of binary conversions.

Binary Converters Some shitty programs just to brush up on my understanding of binary conversions. Supported conversions formats = "unsigned-binary" |

Tim 2 Jan 9, 2022
Todos os exercícios do Curso de Python, do canal Curso em Vídeo, resolvidos em Python, Javascript, Java, C++, C# e mais...

Exercícios - CeV Oferecido por Linguagens utilizadas atualmente O que vai encontrar aqui? ?? Esse repositório é dedicado a armazenar todos os enunciad

Coding in Community 43 Nov 10, 2022
A Python script made for the Python Discord Pixels event.

Python Discord Pixels A Python script made for the Python Discord Pixels event. Usage Create an image.png RGBA image with your pattern. Transparent pi

Stanisław Jelnicki 4 Mar 23, 2022
this is a basic python project that I made using python

this is a basic python project that I made using python. This project is only for practice because my python skills are still newbie.

Elvira Firmansyah 2 Dec 14, 2022