Live data from Hacker News

Python code to solve xkcd 1313 by Peter Norvig

nbviewer.ipython.org

71–75 of 75 posts

Re: Python code to solve xkcd 1313 by Peter Norvig

#71

Judging by the amount of fawning here, this guy must be a HN celebrity. Interesting post nevertheless!

I can only hope, one day, I'd be writing and publishing joyful little hacks like this, to such general applause, instead of eking out a living. I have to say I'm a bit envious here!

Well done to the dude. An inspirational post, in many ways.

Re: Python code to solve xkcd 1313 by Peter Norvig

#72
post #58
post #57

What tool does Norvig use to create this json file? Does iPython have this as a feature (somehow allowing formatted text)?

By "this json file", do you mean the ipython notebook itself? (It's saved as JSON behind-the-scenes. That's what you'll get if you click "download notebook".) If so, yes, that's what a saved ipython notebook is. See: http://ipython.org/notebook.html for an overview of ipython notebooks. You can export it to html, latex, etc using "ipython nbconvert --to ". See: http://ipython.org/ipython-doc/dev/interactive/notebook.…

What's the best way to install ipython on a Mac? Mine's from Macports, and I have ipython notebook, but when I try to use nbconvert I'm told I'm missing pandoc. A 'port install pandoc' wants to install yet another copy of gcc (I have two--including one from Macports for another ipython dependency), ghc, and about three dozen packages prefixed with 'hs'.

Is there any nice bundle of everything you need for ipython, for the Mac, that's both easy to install and uninstall?

Re: Python code to solve xkcd 1313 by Peter Norvig

#73
post #72
post #58

Earlier quoted context omitted.

By "this json file", do you mean the ipython notebook itself? (It's saved as JSON behind-the-scenes. That's what you'll get if you click "download notebook".) If so, yes, that's what a saved ipython notebook is. See: http://ipython.org/notebook.html for an overview of ipython notebooks. You can export it to html, latex, etc using "ipython nbconvert --to ". See: http://ipython.org/ipython-doc/dev/interactive/notebook.…

What's the best way to install ipython on a Mac? Mine's from Macports, and I have ipython notebook, but when I try to use nbconvert I'm told I'm missing pandoc. A 'port install pandoc' wants to install yet another copy of gcc (I have two--including one from Macports for another ipython dependency), ghc, and about three dozen packages prefixed with 'hs'. Is there any nice bundle of everything you need for ipython, for…

If you just want to install pandoc so you can convert things, see: http://johnmacfarlane.net/pandoc/installing.html (There's an OSX binary there)

Seeing as how you already have a functioning install of ipython and a setup you're otherwise happy with, this is probably the easiest route.

Also, just so it's clear what's going on, ipython notebooks and (especially) format conversion are optional (but very useful) parts of ipython. They're not part of the core functionality, so `pandoc` isn't a strict requirement to build ipython.

Otherwise, as long as you don't mind switching the python interpreter, etc as well, look into Anaconda or Canopy. I'm not 100% sure if either comes with pandoc, but they're stand-alone scientific python distributions that make it a good bit easier to get ipython, numpy, matplotlib, etc set up.

Re: Python code to solve xkcd 1313 by Peter Norvig

#74

Earlier quoted context omitted.

That strategy would return results for any phrase not containing "of course". Which would be rather a lot of results in any document. I am envisioning a regex that plucks hashes from emails, for example. Some parts English, some parts cryptographic "noise". Pick the noise from the English (note the inspiration was a nefarious regex scanner for finding bitcoin hashes. I have no intention of building such a thing, but…

I had to recognize English for a cryptography project in college. This was my entire strategy, which the professor advised for rejecting non-English (it turns out recognizing non-English is easier than recognizing English), and works well: 1. Parse the full text of some long book available on Project Gutenberg. Record every trigram that occurs. Frequency is irrelevant; we just want to know whether a trigram occurs or…

How effective was your algo?

Presumably it would false-negative texts with neologisms and spelling errors and such.

There must be trigrams which simply don't appear in dictionary-English? Do you have results posted somewhere.

Re: Python code to solve xkcd 1313 by Peter Norvig

#75
post #73
post #72

Earlier quoted context omitted.

What's the best way to install ipython on a Mac? Mine's from Macports, and I have ipython notebook, but when I try to use nbconvert I'm told I'm missing pandoc. A 'port install pandoc' wants to install yet another copy of gcc (I have two--including one from Macports for another ipython dependency), ghc, and about three dozen packages prefixed with 'hs'. Is there any nice bundle of everything you need for ipython, for…

If you just want to install pandoc so you can convert things, see: http://johnmacfarlane.net/pandoc/installing.html (There's an OSX binary there) Seeing as how you already have a functioning install of ipython and a setup you're otherwise happy with, this is probably the easiest route. Also, just so it's clear what's going on, ipython notebooks and (especially) format conversion are optional (but very useful) parts o…

Thanks for the pandoc link, I'll try that tonight. My ipython does already have notebook, numpy, matplotlib, and more set-up; I didn't realize I was missing anything till I tried nbconvert.

But I've just recently installed all this, and have only kicked it around a little. Mostly, I wanted plotting.

Post reply on HN