8 ms·
Norvig's Python programs to practice or demonstrate skills
- throwaway7645 9y agoNorvig 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.
- dgritsko 9y agoI was curious, so I looked up the SICP review you mentioned: https://www.amazon.com/review/R403HR4VL71K8 https://www.amazon.com/review/R403HR4VL71K8
- cybertronic 9y agoAlso liked this one (referring to sicp too):https://www.amazon.com/gp/review/R2C7L5KHUVHOR2?ref_=glimp_1rv_cl https://www.amazon.com/gp/review/R2C7L5KHUVHOR2?ref_=glimp_1...
- stablemap 9y agoHis website contains a lot of gems: http://norvig.com/ http://norvig.com/ I think the course to which you refer is on Udacity, with Thrun; I found it easier to read the book.
- throwaway7645 9y agoThanks for correcting my mistake! It's def better than most I signed up for!
- nabla9 9y agoEverybody knows about AIMA (Artificial Intelligence, Modern Apporach) but Norvigs PAIP (Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp) is also a gem. It's elegant learn programming, history of AI, and simple old school Common Lisp in the same package. AI methods include GPS, Eliza style chatbots, symbolic math, constraint satisfaction, logic programming, natural language programming.
- flavio81 9y ago>Norvigs PAIP (Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp) is also a gem. It's a wonderful book and it even includes some advanced advice on how to speedup Common Lisp code, which I have not found elsewhere!
- strong_silent_t 9y agoRegarding 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.
- throwaway7645 9y agoI think that's an excellent view of the tradeoffs between the two.
- agumonkey 9y agoI'd like to ask him about a more ml-y python. Same syntax, same tinyness, but less mutable OO at its core.
- stormking 9y agoTry http://coconut-lang.org http://coconut-lang.org Not pure, not perfect, but still great!
- agumonkey 9y agovery nice, thanks
- AlexCoventry 9y agoWow, this plus a persistent data structures library could be almost as much fun as clojure!
- Singletoned 9y ago
- vram22 9y agoLast I read (a while ago), he was Director of Research at Google (not just AI). This was after being Director of Search (Quality), IIRC.
- pvg 9y ago'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 9y agoThis book looks interesting, but it's ridiculously overpriced for a book from 1978.
- pvg 9y agoYes, 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.
- qntty 9y agoIn fact, you won't find any mention of red-black trees anywhere in the book, because the term wasn't invented until a few months after it was published :P
- jypepin 9y agoNorvig'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%20of%20Code.ipynb https://nbviewer.jupyter.org/url/norvig.com/ipython/Advent%2...
- carreau 9y agoYou 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.
- cup-of-tea 9y agoThey are also run directly on github, but you can't edit them. Still useful if you just want to read, though.
- carreau 9y agoTechnically No, they are just rendered on GitHub (using nbconvert internally, so more like nbviewer.org). What you see on GH is the result of last run by Peter (which may be forged, or out of date). But thanks for pointing it out.
- cup-of-tea 9y agoOh, I thought that they were run because they had the output, which I didn't think would be commited to the repository. Good to know.
- kovek 9y agoIt is unclear how you would `pip install numpy` on mybinder.org
- carreau 9y ago`!pip install numpy` in a notebook, or "new" > "terminal" and you have a shell...
- smortaz 9y agoYou can also run them on Azure Notebooks which is basically a free hosted jupyter notebook service for anyone to use: https://notebooks.azure.com/smortaz/libraries/norvig-pytudes https://notebooks.azure.com/smortaz/libraries/norvig-pytudes basically 1) click the link 2) click clone 3) sign in (any gmail, msft id), then go to the notebooks directly and run them. You can also click Terminal for shell prompt. The sign-in is required since you can edit the notebooks, store/modify data etc.
- deepGem 9y agoHis Design of Computer programs course on Udacity is amazing. https://in.udacity.com/course/design-of-computer-programs--cs212 https://in.udacity.com/course/design-of-computer-programs--c...
- dpflan 9y agoI second this. It's interesting and informative to watch him break down programs and to see his code. Plus, you get treated to selections from his Hawaiian shirt collection.
- zerr 9y agoThe 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 9y agoTried 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 9y agoSome 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 9y agoAt 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.
- rb808 9y agoIs 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 9y agoWell 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.
- maxerickson 9y agoI imagine the best way to make it educational would be to skip the problems you know how to solve and then try to solve the others without a whole lot of "cheating". Obviously looking at resources to learn approaches to solving the problem isn't cheating, but there is some value in spending time just trying to figure out an approach before doing that.
- narimiran 9y ago> Is the adventofcode.com fun/educational/worthwhile? For me, the answer to all three questions is - yes. It depends on your previous knowledge, so some problems might seem too easy and/or some other problems might be too hard. If you are an experienced programmer, maybe use AoC to learn/practice some language you didn't use before?
- cdancette 9y agoI 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 9y agoHe shows a more complete version in another essay http://norvig.com/lispy2.html http://norvig.com/lispy2.html
- b0rsuk 9y agoI 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 ?
- nafizh 9y agoYou should check out Norvig's design of computer programs course on Udacity (https://www.udacity.com/course/design-of-computer-programs--cs212 https://www.udacity.com/course/design-of-computer-programs--...) where he uses these kinds of puzzle programs to teach programming design concepts. It is a hard but really rewarding course.
- coldtea 9y ago>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 ? By virtue of being better written and more thought out. Also, they are not "programming challenges". They are solutions to programming challenges.
- stiff 9y agoPeter 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.
- Myrmornis 9y agoLiterate 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.
- abecedarius 9y agoIs there a mode to rerun everything on every update? That's how my https://github.com/darius/halp https://github.com/darius/halp works, and it's fine for working out code with cheap test cases. You wouldn't want to do that for data analyses that take even a second, but I've found myself using it a lot to develop code.
- emj 9y agoYes 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 9y agoYes, 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.
- ticotico 9y agoWhat would be a similar resource but for Ruby?
- Lordarminius 9y agohttp://rubyquiz.com/ http://rubyquiz.com/ is pretty good.
- brian_spiering 9y agoHere 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 9y agoThe majority of the python stuff is contributed by others source: was a contributor
- deleted 9y ago[deleted]
- kwillets 9y agoHis 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.
- bhollan 9y agoAm I the only one getting 500 for this link?
- grzm 9y agoIt's not just this page. GitHub is apparently having issues right now. https://status.github.com/messages https://status.github.com/messages
- bhollan 9y agoI had checked that page when I posted my comment. Somehow the issue got fixed before that note got posted. Thanks!
- bhollan 9y agoWorking now
- dfee 9y agoThe 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 9y ago`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 9y agoPlease 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 9y agoTop of the file: """ Game of Set (Peter Norvig 2010-2015) """ It's the name of the problem being solved.
- dfee 9y agoYeah, `game.py` would've been great!
- fastbeef 9y agoKind of OT, but... according to his CV Norvig was the Chief Designer for Harlequin?! http://norvig.com/resume.html http://norvig.com/resume.html