
Norvig's Python programs to practice or demonstrate skills - federicoponzi
https://github.com/norvig/pytudes
======
throwaway7645
Norvig is a beast. For those that don't know, he is high up in Google Research
(AI director I believe) and also wrote the #1 AI textbook. He has the #1 AI
course on coursera or edx too (can't remember which one). He's a big lisp
advocate (look at his review of SICP on amazon), but also has the programs for
his books in Java, and Python.

~~~
strong_silent_t
Regarding lisp, he made a post about language choice here:
[https://news.ycombinator.com/item?id=1803815](https://news.ycombinator.com/item?id=1803815)

 _I think Lisp still has an edge for larger projects and for applications
where the speed of the compiled code is important. But Python has the edge
(with a large number of students) when the main goal is communication, not
programming per se. In terms of programming-in-the-large, at Google and
elsewhere, I think that language choice is not as important as all the other
choices: if you have the right overall architecture, the right team of
programmers, the right development process that allows for rapid development
with continuous improvement, then many languages will work for you; if you don
't have those things you're in trouble regardless of your language choice. _

~~~
agumonkey
I'd like to ask him about a more ml-y python. Same syntax, same tinyness, but
less mutable OO at its core.

~~~
stormking
Try [http://coconut-lang.org](http://coconut-lang.org)

Not pure, not perfect, but still great!

~~~
Singletoned
It's like someone has looked at Python and thought "Python is too easy to
read. Let's add LOTS more syntax to it".

------
b0rsuk
I get it that Peter Norvig is a very smart programmer. But can someone explain
to me - like a farmer to his cow - how do these resources differ from typical
programming challenges found on the web ?

How will these make me a better programmer ? Is each designed to teach a
different programming concept or technique ? Are they useful in fields lower
than machine learning or AI ?

What's the benefit of a program that detects palindromes ?

~~~
stiff
Peter Norvig has this unique style where he explains his design process in
detail, including exploring the problem on example cases, writing multiple
solutions, the thinking involved in moving from one solution to the next one,
including profiling and finding bottlenecks etc., you see how he goes about
problem solving and he is a master problem solver. In fact his writing
provides a good opportunity to reflect on what designing programs even means:
investigating and choosing trade-offs, choosing an adequate representation
(data structure) for a problem etc. This illustrates on a small scale how a
lot of the most serious software engineering happens, the engineering where
you actually have a definite, hard problem to solve, rather than just making
the program pretty by criteria on which there is no agreement etc.

He does this not only in those notebooks but for example also in his
"Paradigms Of Artificial Intelligence Programming" book. I have not seen this
done to any serious extent in any algorithm textbook or tutorials.

~~~
AnkhMorporkian
I code Python professionally (and passionately), and would consider myself
quite experienced. His code in ' When Cheryl Met Eve: A Birthday Story' is the
most beautifully constructed stuff in the world. That sort of stuff isn't
about coding ability, it's about a reasoning process that some people have
developed to such an extent that it's innately beautiful no matter how it's
expressed. I'm sure his javascript solution would be nearly as beautiful.

~~~
gozzoo
> His code in ' When Cheryl Met Eve: A Birthday Story' is the most beautifully
> constructed stuff in the world.

Where is this published? I couldn't look it up.

~~~
tclancy
Isn't it right here?
[https://github.com/norvig/pytudes/blob/master/ipynb/Cheryl-a...](https://github.com/norvig/pytudes/blob/master/ipynb/Cheryl-
and-Eve.ipynb)

------
deepGem
His Design of Computer programs course on Udacity is amazing.

[https://in.udacity.com/course/design-of-computer-programs--
c...](https://in.udacity.com/course/design-of-computer-programs--cs212)

~~~
zerr
The problem with this course is that it is quite boring if you're not
interested in given subjects - e.g. Poker lectures make me sleepy.

~~~
Err_Eek
Tried to go through the course a few years ago. In my case it was the regex
bit. Trying to write the code is a massive chore with with very little payoff
for going through it, and needing to go through the instructions several times
in a row. Gave up on the course there.

~~~
abecedarius
Some people gave up on that section (week 5 of 10) and went on with the rest
of the course. That seems to work out OK.

(I felt a little bad about these reactions because I'd helped with that code.
In its defense, I've also been told by a couple of people that they gained a
lot by working through it.)

~~~
Err_Eek
At one point I a friend was mentioning the regex golf
[https://xkcd.com/1313/](https://xkcd.com/1313/) comic and how some insane
person on the internet solved it. I mentioned my pains with the regex bit of
the Design of Computer Programs course, and how Norvig had some Chtulhu like
ability to write regexes that befuddle mortal minds. Lo and behold, it had
been Norvig all along solving that. Python notebook available in the pytudes
above.

------
Myrmornis
Literate programming / ipython notebooks make me very uncomfortable.

Primarily the problem is that it's a living body of mutable state -- like an
Excel spreadsheet, except it doesn't auto-update -- if I poke at some bit of
it, and then re-evaluate a cell, some state will change, probably. And then
maybe other cells' outputs will be invalid. Hmm, maybe I should re-evaluate
the whole notebook? Oh, but some of the cells contain shell commands, for
example to download a dictionary file from norvig.com. Do I want to do that?
Maybe I should just undo the change I made. The ipynb is in git of course. But
instead of a nice diff showing lines of code, the python code is held inside
some JSON document.

Ipython notebook is beautiful technology, the front-end is really-well done.
But accumulating all that mutable state goes against all my instincts as a
programmer. I prefer editing .py files in my text editor, with Make when
necessary. And then creating output from input with a single, transient,
execution.

~~~
emj
Yes this is a problem when the notebooks grow, but where do you draw the line,
the work flow Jupyter uses is perfect for exploratory coding, but it gets
complicated quickly

~~~
Myrmornis
Yes, to be honest I do much more programming than exploratory data analysis
currently. FWIW, here's how I use it when I want to use Jupyter:

\- Write all my python code in .py files as usual.

\- The Jupyter notebook contains calls to functions generating
graphical/HTML/etc output, nothing else.

\- Either use one of the various `reload*` functionalities to update the state
of the persistent python process, or use `ipython console --existing` to
create a conventional ipython shell sharing the same kernel as Jupyter and
evaluate code in there.

------
carreau
You can run these notebooks for free in the cloud (on MyBinder.org provided by
the Jupyter team). Just head there:
[https://mybinder.org/v2/gh/norvig/pytudes/master](https://mybinder.org/v2/gh/norvig/pytudes/master)
You may need to `pip install numpy`. Watch out images are ephemeral.

~~~
keont
What the fuck is this magic, and how did I not know about this? I've been
looking so long for something like this... Does it exist for scala? Java? This
is amazing!!!

~~~
physicsyogi
There's a nice Jupyter kernel for Clojure:
[https://github.com/didiercrunch/lein-
jupyter](https://github.com/didiercrunch/lein-jupyter).

------
jypepin
Norvig's notebooks are my favorite resource for code reading. He has so much
of them, written is such a nice, clean, clever but yet understandable and
readable way, it's always a pleasure and amazing learning experience to go
through them.

For example, going through his notebook for code advent (the first linked)
[1].

[1]
[https://nbviewer.jupyter.org/url/norvig.com/ipython/Advent%2...](https://nbviewer.jupyter.org/url/norvig.com/ipython/Advent%20of%20Code.ipynb)

------
cdancette
I really like his (How to Write a (Lisp) Interpreter (in Python)) :
[http://norvig.com/lispy.html](http://norvig.com/lispy.html)

You learn to build a lisp interpreter in about 100 lines of python (you miss a
few features like macros, but it's still quite complete). Very nice to learn
how language interpretation works

~~~
Recursing
He shows a more complete version in another essay
[http://norvig.com/lispy2.html](http://norvig.com/lispy2.html)

------
pvg
'Etudes for Programmers' itself remains an interesting read and entertaining
problem set. And not a single one is about implementing a Red-Black tree from
memory.

~~~
pmoriarty
This book looks interesting, but it's ridiculously overpriced for a book from
1978.

~~~
pvg
Yes, I'm not sure why it's never been reprinted or why used copies appreciate
like they're made of pure bitcoin. There is a copy kicking around on libgen.

------
rb808
Is the adventofcode.com fun/educational/worthwhile? I see it starts again Dec
1. I like doing things like this but end up regretting it as it sucks too much
time solving unnecessary problems.

~~~
wellpast
Well I would consider any puzzle type problems technically "unnecessary" but I
thought the adventofcode puzzles in 2016 were fun, well designed and tapped
into some good CS algorithm and theory stuff.

------
brian_spiering
Here is code for "Artificial Intelligence: A Modern Approach"
[https://github.com/aimacode](https://github.com/aimacode)

Norvig wrote some of the Python version [https://github.com/aimacode/aima-
python](https://github.com/aimacode/aima-python)

~~~
thundergolfer
The majority of the python stuff is contributed by others

source: was a contributor

------
ticotico
What would be a similar resource but for Ruby?

~~~
Lordarminius
[http://rubyquiz.com/](http://rubyquiz.com/) is pretty good.

------
kwillets
His regex golf seems kind of strange; he never mentions suffix trees. It seems
like a fairly straightforward process to go through and mark the shortest
distinguishing infix for each string in a generalized suffix tree.

------
dfee
The algorithms I browsed make sense, but his coding style is peculiar, and
somewhat un-pythonic.

For instance:
[https://github.com/norvig/pytudes/blob/master/py/SET.py](https://github.com/norvig/pytudes/blob/master/py/SET.py)

Why the CAPS name? Why are we defining `test` if we’re just running it on the
next line - or rather, why are running the test in that same file as it’s
definition, and then running an example 100k times?

Any professional python developer will know this, but when an adventuring
friend calls me to help him debug something, with code modeled on what he’s
seen in examples like these, I’ll likely just throw my hands up.

On the flip side, this isn’t bad for showing how something works, and the
cognitive overload for a beginner to “get to the meat” if he’d used `argparse`
or `click` might be a bit high.

~~~
gary_bernhardt
`set` is a built-in. He probably didn't want to smash it.

Defining a function and immediately calling it prevents pollution of module
scope. Without it, `photo` would be exported.

The tests are in the same file because it makes the example self-contained, I
assume.

The experiments are run 100,000 times because they have a random component and
this exercises the system.

~~~
dfee
Please re-read my comment. I understand what he did, but my points stand.

The name `SET` conveys little. Running the exercise in the same file is OK as
it’s not in a module, but again - the work demonstrates algorithms well
enough, but I can’t see this coding style as “smart” or “clean”. It’s not.

~~~
gary_bernhardt
Top of the file:

""" Game of Set (Peter Norvig 2010-2015) """

It's the name of the problem being solved.

~~~
dfee
Yeah, `game.py` would've been great!

------
fastbeef
Kind of OT, but... according to his CV Norvig was the Chief Designer for
Harlequin?!

[http://norvig.com/resume.html](http://norvig.com/resume.html)

------
bhollan
Am I the only one getting 500 for this link?

~~~
grzm
It's not just this page. GitHub is apparently having issues right now.

[https://status.github.com/messages](https://status.github.com/messages)

~~~
bhollan
I had checked that page when I posted my comment. Somehow the issue got fixed
before that note got posted. Thanks!

