diff --git a/py/pytudes.py b/py/pytudes.py index 052081d..b9e8325 100644 --- a/py/pytudes.py +++ b/py/pytudes.py @@ -1,7 +1,12 @@ # Run "python pytudes.py" to create README.md for pytudes -def nb(title, url, comment=''): +def nbs(category, *notebooks): + """Make a table entry for jupyter/ipython notebooks.""" + header = f'|Run|Year|{category}|\n|---|----|---|\n' + return header + '\n'.join(nb(*line) for line in notebooks) + +def nb(title, year, url, comment=''): """Make a markdown table entry for a jupyter/ipython notebook.""" urlb = f'/blob/master/ipynb/{url}' co = f'[co](https://colab.research.google.com/github/norvig/pytudes{urlb})' @@ -9,17 +14,22 @@ def nb(title, url, comment=''): my = f'[my](https://mybinder.org/v2/gh/norvig/pytudes/master?filepath=ipynb%2F{url})' nb = f'[nb](https://nbviewer.jupyter.org/github/norvig/pytudes{urlb})' ti = f'{title}' - return f'| {co} {dn} {my} {nb} | {ti} |' - + if year == 2020: year = f'{year}' + return f'| {co} {dn} {my} {nb} | {year} | {ti} |' +def pys(*pyfiles): + header = '| File | Description | Documentation |\n|:--|:----|----|\n' + return header + '\n'.join(py(*line) for line in pyfiles) + def py(url, description, doc=''): """Make a markdown table entry for a .py file.""" if doc: doc = f'[documentation]({doc})' return f'|[{url}](/blob/master/py/{url})|*{description}*|{doc}|' -body = f''' -
Peter Norvig
MIT License
2015-2020
+body = f""" + +
Peter Norvig
MIT License
2015-2020
# pytudes @@ -38,101 +48,99 @@ Some programs are in Jupyter (`.ipynb`) notebooks, some in `.py` files. For each # Index of Jupyter (IPython) Notebooks -|Run|Programming Examples| -|---|--| -{nb('Advent of Code 2018', 'Advent-2018.ipynb', 'Puzzle site with a coding puzzle each day for Advent 2018 ')} -{nb('Advent of Code 2017', 'Advent%202017.ipynb', 'Puzzle site with a coding puzzle each day for Advent 2017')} -{nb('Advent of Code 2016', 'Advent%20of%20Code.ipynb', 'Puzzle site with a coding puzzle each day for Advent 2016*')} -{nb("Beal's Conjecture Revisited", 'Beal.ipynb', "A search for counterexamples to Beal's Conjecture")} -{nb('Bike Speed Versus Grade', 'Bike%20Speed%20versus%20Grade.ipynb', 'How fast can I bike as the route gets steeper?')} -{nb("Can't Stop", 'Cant-Stop.ipynb', 'Optimal play in a dice board game')} -{nb('Chaos with Triangles', 'Sierpinski.ipynb', 'A surprising appearance of the Sierpinski triangle in a random walk between vertexes')} -{nb("Conway's Game of Life", 'Life.ipynb', 'The cellular automata zero-player game')} -{nb('Dice Baseball', 'Dice%20Baseball.ipynb', 'Simulating baseball games')} -{nb('Generating Mazes', 'Maze.ipynb', 'Make a maze by generating a random tree superimposed on a grid')} -{nb('Photo Focal Lengths', 'PhotoFocalLengths.ipynb', 'Generate charts of what focal lengths were used on a photo trip.')} -{nb('Pickleball Tournament', 'Pickleball.ipynb', 'Scheduling a doubles tournament fairly and efficiently')} -{nb('Project Euler Utilities', 'Project%20Euler%20Utils.ipynb', 'My utility functions for the Project Euler problems, including `Primes` and `Factors`')} -{nb('Properly Ordered Card Hands', 'Orderable%20Cards.ipynb', 'Can you get your hand of cards into a nice order with just one move?')} -{nb('Tracking Trump: Electoral Votes', 'Electoral%20Votes.ipynb', 'How many electoral votes would Trump get if he wins the state where he has positive net approval?')} -{nb('Weighing Twelve Balls', 'TwelveBalls.ipynb', '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')} -{nb('WWW: Who Will Win (NBA Title)?', 'WWW.ipynb', 'Computing the probability of winning the NBA title, for my home town Warriors, or any other team')} +{nbs('Programming Examples', +('Advent of Code 2018', 2018, 'Advent-2018.ipynb', 'Puzzle site with a coding puzzle each day for Advent 2018 '), +('Advent of Code 2017', 2017, 'Advent%202017.ipynb', 'Puzzle site with a coding puzzle each day for Advent 2017'), +('Advent of Code 2016', 2016, 'Advent%20of%20Code.ipynb', 'Puzzle site with a coding puzzle each day for Advent 2016*'), +("Beal's Conjecture Revisited", 2018, 'Beal.ipynb', "A search for counterexamples to Beal's Conjecture"), +('Bike Speed Versus Grade', 2020, 'Bike%20Speed%20versus%20Grade.ipynb', 'How fast can I bike as the route gets steeper?'), +("Can't Stop", 2018, 'Cant-Stop.ipynb', 'Optimal play in a dice board game'), +('Chaos with Triangles', 2019, 'Sierpinski.ipynb', 'A surprising appearance of the Sierpinski triangle in a random walk between vertexes'), +("Conway's Game of Life", 2017, 'Life.ipynb', 'The cellular automata zero-player game'), +('Generating and Solving Mazes', 2020, 'Maze.ipynb', 'Make a maze by generating a random tree superimposed on a grid and solve it.'), +('Photo Focal Lengths', 2020, 'PhotoFocalLengths.ipynb', 'Generate charts of what focal lengths were used on a photo trip.'), +('Pickleball Tournament', 2018, 'Pickleball.ipynb', 'Scheduling a doubles tournament fairly and efficiently'), +('Project Euler Utilities', 2017, 'Project%20Euler%20Utils.ipynb', 'My utility functions for the Project Euler problems, including `Primes` and `Factors`'), +('Tracking Trump: Electoral Votes', 2020, 'Electoral%20Votes.ipynb', 'How many electoral votes would Trump get if he wins the state where he has positive net approval?'))} + +{nbs('Logic and Number Puzzles', +('Cryptarithmetic', 2014, 'Cryptarithmetic.ipynb', 'Substitute digits for letters and make NUM + BER = PLAY'), +('Four 4s, Five 5s, Equilength Numbers, and Countdown to 2016', 2020, 'Countdown.ipynb', 'Solving the equation 10 _ 9 _ 8 _ 7 _ 6 _ 5 _ 4 _ 3 _ 2 _ 1 = 2016. From an Alex Bellos puzzle'), +('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'), +("Sol Golomb's Rectangle Puzzle", 2014, 'Golomb-Puzzle.ipynb', 'A Puzzle involving placing rectangles of different sizes inside a square'), +("When is Cheryl's Birthday? (new: Mad Cheryl)", 2020, 'Cheryl.ipynb', "Solving the *Cheryl's Birthday* logic puzzle"), +('When Cheryl Met Eve: A Birthday Story', 2015, 'Cheryl-and-Eve.ipynb', "Inventing new puzzles in the Style of Cheryl's Birthday"), +('xkcd 1313: Regex Golf', 2015, 'xkcd1313.ipynb', 'Find the smallest regular expression; inspired by Randall Munroe'), +('xkcd 1313: Regex Golf (Part 2: Infinite Problems)', 2015, 'xkcd1313-part2.ipynb', 'Regex Golf: better, faster, funner. With Stefan Pochmann.'))} + +{nbs('The Riddler (from 538)', +('Riddler: Battle Royale', 2017, 'Riddler%20Battle%20Royale.ipynb', 'A puzzle involving allocating your troops and going up against an opponent'), +('Riddler: Flipping Cards; A Guessing Game', 2020, 'flipping.ipynb', 'Can you go through a deck of cards, guessing higher or lower correctly for each card?'), +('Riddler: Lottery', 2019, 'RiddlerLottery.ipynb', 'Can you find what lottery number tickets these five friends picked?'), +('Riddler: How Many Soldiers to Beat the Night King?', 2019, 'NightKing.ipynb', 'A battle between the army of the dead and the army of the living'), +('Riddler: Properly Ordered Card Hands', 2018, 'Orderable%20Cards.ipynb', 'Can you get your hand of cards into a nice order with just one move?'), +('Riddler: The Puzzle of the Misanthropic Neighbors', 2017, 'Mean%20Misanthrope%20Density.ipynb', 'How crowded will this neighborhood be, if nobody wants to live next door to anyone else?'), +('Riddler: Tour de 538', 2020, 'TourDe538.ipynb', 'Solve a puzzle involving the best pace for a bicycle race.'), +('Riddler: Weighing Twelve Balls', 2020, 'TwelveBalls.ipynb', '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'))} + +{nbs('Word Puzzles', +('Boggle / Inverse Boggle', 2020, 'Boggle.ipynb', 'Find all the words on a Boggle board; then find a board with a lot of words'), +('Crossword Game: Refactoring a Scrabble Program', 2017, 'Scrabble.ipynb', 'Refactoring the Scrabble / Word with Friends game from Udacity 212'), +('Chemical Element Spelling', 2020, 'ElementSpelling.ipynb', 'Spelling words using the chemical element symbols, like CoIn'), +('Gesture Typing', 2017, 'Gesture%20Typing.ipynb', 'What word has the longest path on a gesture-typing smartphone keyboard?'), +('Ghost: A Word game', 2017, 'Ghost.ipynb', 'The word game Ghost (add letters, try to avoid making a word)'), +('How to Do Things with Words: NLP in Python', 2018, 'How%20to%20Do%20Things%20with%20Words.ipynb', 'Spelling Correction, Secret Codes, Word Segmentation, and more'), +("Let's Code About Bike Locks", 2015, 'Fred%20Buns.ipynb', 'A tale of a bicycle combination lock that uses letters instead of digits. Inspired by Bike Snob NYC'), +('Spelling Bee', 2020, 'SpellingBee.ipynb', 'Find the highest-scoring board for the NY Times Spelling Bee puzzle'), +('Translating English into Propositional Logic', 2017, 'PropositionalLogic.ipynb', 'Automatically convert informal English sentences into formal Propositional Logic'), +("World's Longest Palindrome", 2017, 'pal3.ipynb', 'Searching for a long Panama-style palindrome, this time letter-by-letter'), +("World's Shortest Portmantout Word", 2020, 'Portmantout.ipynb', 'Find a word that squishes together a bunch of words'), +('xkcd 1970: Name Dominoes', 2018, 'xkcd-Name-Dominoes.ipynb', 'Lay out dominoes legally; the dominoes have people names, not numbers'))} + +{nbs('Probability, Uncertainty, and Counting', +('A Concrete Introduction to Probability', 2018, 'Probability.ipynb', 'Code and examples of the basic principles of Probability Theory'), +('Probability, Paradox, and the Reasonable Person Principle', 2016, 'ProbabilityParadox.ipynb', 'Some classic paradoxes in Probability Theory, and how to think about disagreements'), +('Estimating Probabilities with Simulations', 2020, 'ProbabilitySimulation.ipynb', 'When the sample space is too complex, simulations can estimate probabilities'), +('The Devil and the Coin Flip Game', 2019, 'Coin%20Flip.ipynb', 'How to beat the Devil at his own game'), +('Dice Baseball', 2020, 'Dice%20Baseball.ipynb', 'Simulating baseball games'), +('Economics Simulation', 2018, 'Economics.ipynb', 'A simulation of a simple economic game'), +("Euler's Sum of Powers Conjecture", 2018, "Euler's%20Conjecture.ipynb", 'Solving a 200-year-old puzzle by finding integers that satisfy a5 + b5 + c5 + d5 = e5'), +('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'), +('The Unfinished Game .... of Risk', 2020, "risk.ipynb", "Determining who is likely to win an interminably long game of Risk"), +('WWW: Who Will Win (NBA Title)?', 2019, 'WWW.ipynb', 'Computing the probability of winning the NBA title, for my home town Warriors, or any other team'))} -|Run | Logic and Number Puzzles| -|--|---| -{nb('Boggle / Inverse Boggle', 'Boggle.ipynb', 'Find all the words on a Boggle board; then find a board with a lot of words')} -{nb('Chemical Element Spelling', 'ElementSpelling.ipynb', 'Spelling words using the chemical element symbols, like CoIn')} -{nb('Cryptarithmetic', 'Cryptarithmetic.ipynb', 'Substitute digits for letters and make NUM + BER = PLAY')} -{nb('Four 4s, Five 5s, and Countdown to 2016', 'Countdown.ipynb', 'Solving the equation 10 _ 9 _ 8 _ 7 _ 6 _ 5 _ 4 _ 3 _ 2 _ 1 = 2016. From an Alex Bellos puzzle')} -{nb('The Devil and the Coin Flip Game', 'Coin%20Flip.ipynb', 'How to beat the Devil at his own game')} -{nb('Flipping Cards: A Guessing Game', 'flipping.ipynb', 'Can you go through a deck of cards, guessing higher or lower correctly for each card?')} -{nb('Gesture Typing', 'Gesture%20Typing.ipynb', 'What word has the longest path on a gesture-typing smartphone keyboard?')} -{nb('Ghost', 'Ghost.ipynb', 'The word game Ghost (add letters, try to avoid making a word)')} -{nb('How Many Soldiers Do You Need to Beat the Night King?', 'NightKing.ipynb', 'Investigasting a battle between the army of the dead and the army of the living')} -{nb("Let's Code About Bike Locks", 'Fred%20Buns.ipynb', 'A tale of a bicycle combination lock that uses letters instead of digits. Inspired by Bike Snob NYC')} -{nb('Pairing Socks', 'Socks.ipynb', 'What is the probability that you will be able to pair up socks as you randomly pull them out of the dryer?')} -{nb('Portmantout Words', 'Portmantout.ipynb', 'Find a long word that squishes together a bunch of words')} -{nb('The Puzzle of the Misanthropic Neighbors', 'Mean%20Misanthrope%20Density.ipynb', 'How crowded will this neighborhood be, if nobody wants to live next door to anyone else?')} -{nb('Refactoring a Crossword Game Program', 'Scrabble.ipynb', 'Refactoring the Scrabble / Word with Friends game from Udacity 212')} -{nb('Riddler: Battle Royale', 'Riddler%20Battle%20Royale.ipynb', 'A puzzle involving allocating your troops and going up against an opponent')} -{nb('Riddler Lottery', 'RiddlerLottery.ipynb', 'Can you find what lottery number tickets these five friends picked?')} -{nb('Riddler: Tour de 538', 'TourDe538.ipynb', 'Solve a puzzle involving the best pace for a bicycle race.')} -{nb('Sicherman Dice', 'Sicherman%20Dice.ipynb', 'Find a pair of dice that is like a regular pair of dice, only different')} -{nb("Sol Golomb's Rectangle Puzzle", 'Golomb-Puzzle.ipynb', 'A Puzzle involving placing rectangles of different sizes inside a square')} -{nb('Spelling Bee', 'SpellingBee.ipynb', 'Find the highest-scoring board for the NY Times Spelling Bee puzzle')} -{nb('Translating English Sentences into Propositional Logic Statements', 'PropositionalLogic.ipynb', 'Automatically convert informal English sentences into formal Propositional Logic')} -{nb('How to Do Things with Words: NLP in Python', 'How%20to%20Do%20Things%20with%20Words.ipynb', 'Spelling Correction, Secret Codes, Word Segmentation, and more')} -{nb('When Cheryl Met Eve: A Birthday Story', 'Cheryl-and-Eve.ipynb', "Inventing new puzzles in the Style of Cheryl's Birthday")} -{nb("When is Cheryl's Birthday?", 'Cheryl.ipynb', "Solving the *Cheryl's Birthday* logic puzzle")} -{nb("World's Longest Palindrome", 'pal3.ipynb', 'Searching for a long Panama-style palindrome, this time letter-by-letter')} -{nb('xkcd 1313: Regex Golf (Part 2: Infinite Problems)', 'xkcd1313-part2.ipynb', 'Regex Golf: better, faster, funner. With Stefan Pochmann')} -{nb('xkcd 1313: Regex Golf', 'xkcd1313.ipynb', 'Find the smallest regular expression; inspired by Randall Monroe')} -{nb('xkcd 1970: Name Dominoes', 'xkcd-Name-Dominoes.ipynb', 'Lay out dominoes legally; the dominoes have people names, not numbers')} - - -|Run|Math Concepts| -|--|--| -{nb('A Concrete Introduction to Probability', 'Probability.ipynb', 'Code and examples of the basic principles of Probability Theory')} -{nb('Probability, Paradox, and the Reasonable Person Principle', 'ProbabilityParadox.ipynb', 'Some classic paradoxes in Probability Theory, and how to think about disagreements')} -{nb('Estimating Probabilities with Simulations', 'ProbabilitySimulation.ipynb', 'When the sample space is too complex, simulations can estimate probabilities')} -{nb('Economics Simulation', 'Economics.ipynb', 'A simulation of a simple economic game')} -{nb("Euler's Sum of Powers Conjecture", "Euler's%20Conjecture.ipynb", 'Solving a 200-year-old puzzle by finding integers that satisfy a5 + b5 + c5 + d5 = e5')} -{nb('How to Count Things', 'How%20To%20Count%20Things.ipynb', 'Combinatorial math: how to count how many things there are, when there are a lot of them')} -{nb('Symbolic Algebra, Simplification, and Differentiation', 'Differentiation.ipynb', 'A computer algebra system that manipulates expressions, including symbolic differentiation')} - - -|Run|Computer Science Algorithms and Concepts| -|--|--| -{nb('Bad Grade, Good Experience', 'Snobol.ipynb', 'As a student, did you ever get a bad grade on a programming assignment? (Snobol, Concordance)')} -{nb('BASIC Interpreter', 'BASIC.ipynb', 'How to write an interpreter for the BASIC programming language')} -{nb('The Convex Hull Problem', 'Convex%20Hull.ipynb', 'A classic Computer Science Algorithm')} -{nb('The Stable Matching Problem', 'StableMatching.ipynb', 'What is the best way to pair up two grpups with each other, obeying preferences?')} -{nb('The Traveling Salesperson Problem', 'TSP.ipynb', 'Another of the classics')} +{nbs('Computer Science Algorithms and Concepts', +('Bad Grade, Good Experience', 2017, 'Snobol.ipynb', 'As a student, did you ever get a bad grade on a programming assignment? (Snobol, Concordance)'), +('BASIC Interpreter', 2017, 'BASIC.ipynb', 'How to write an interpreter for the BASIC programming language'), +('The Convex Hull Problem', 2017, 'Convex%20Hull.ipynb', 'A classic Computer Science Algorithm'), +('The 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 that manipulates expressions, including symbolic differentiation'), +('The Traveling Salesperson Problem', 2018, 'TSP.ipynb', 'Another of the classics'))} # Index of Python Files +{pys( +('beal.py', "Search for counterexamples to Beal's Conjecture", 'http://norvig.com/beal.html'), +('docex.py', 'An obsolete framework for running unit tests, similar to `doctest`'), +('ibol.py', 'An Exercise in Species Barcoding', 'http://norvig.com/ibol.html'), +('lettercount.py', 'Convert Google Ngram Counts to Letter Counts', 'http://norvig.com/mayzner.html'), +('lis.py', 'Lisp Interpreter written in Python', 'http://norvig.com/lispy.html'), +('lispy.py', 'Even Better Lisp Interpreter written in Python', 'http://norvig.com/lispy2.html'), +('lispytest.py', 'Tests for Lisp Interpreters'), +('pal.py', 'Find long palindromes', 'http://norvig.com/palindrome.html'), +('pal2.py', 'Find longer palindromes', 'http://norvig.com/palindrome.html'), +('pal3.py', 'Find even longer palindromes', 'http://norvig.com/palindrome.html'), +('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', 'http://norvig.com/SET.html'), +('spell.py', 'Spelling corrector', 'http://norvig.com/spell-correct.html'), +('sudoku.py', 'Program to solve sudoku puzzles', 'http://norvig.com/sudoku.html'), +('testaccum.py', 'Tests for my failed Python `accumulation display` proposal', 'http://norvig.com/pyacc.html'), +('yaptu.py', 'Yet Another Python Templating Utility'))} -| File | Description | Documentation | -|:--------|:-------------------|----| -{py('beal.py', "Search for counterexamples to Beal's Conjecture", 'http://norvig.com/beal.html')} -{py('docex.py', 'A framework for running unit tests, similar to `doctest`')} -{py('ibol.py', 'An Exercise in Species Barcoding', 'http://norvig.com/ibol.html')} -{py('lettercount.py', 'Convert Google Ngram Counts to Letter Counts', 'http://norvig.com/mayzner.html')} -{py('lis.py', 'Lisp Interpreter written in Python', 'http://norvig.com/lispy.html')} -{py('lispy.py', 'Even Better Lisp Interpreter written in Python', 'http://norvig.com/lispy2.html')} -{py('lispytest.py', 'Tests for Lisp Interpreters')} -{py('pal.py', 'Find long palindromes', 'http://norvig.com/palindrome.html')} -{py('pal2.py', 'Find longer palindromes', 'http://norvig.com/palindrome.html')} -{py('pal3.py', 'Find even longer palindromes', 'http://norvig.com/palindrome.html')} -{py('pytudes.py', 'Pre-process text to generate this README.md file.')} -{py('py2html.py', 'Pretty-printer to format Python files as html')} -{py('SET.py', 'Analyze the card game SET', 'http://norvig.com/SET.html')} -{py('spell.py', 'Spelling corrector', 'http://norvig.com/spell-correct.html')} -{py('sudoku.py', 'Program to solve sudoku puzzles', 'http://norvig.com/sudoku.html')} -{py('testaccum.py', 'Tests for my failed Python `accumulation display` proposal', 'http://norvig.com/pyacc.html')} -{py('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](https://books.google.com/books/about/Etudes_for_programmers.html?id=u89WAAAAMAAJ) @@ -140,8 +148,8 @@ by [Charles Wetherell](http://demin.ws/blog/english/2012/08/25/interview-with-ch that was very influential to me when I was first learning to program. I still have my copy. ![](https://images-na.ssl-images-amazon.com/images/I/51ZnZH29dvL._SX394_BO1,204,203,200_.jpg) -''' +""" output = 'README.md' with open(output, 'w') as out: - print(f'Wrote {output}; {out.write(body)} characters') \ No newline at end of file + print(f'Wrote {output}; {out.write(body)}, characters') \ No newline at end of file