Help me puzzle-hack with Python!
February 28, 2008 12:41 PM   Subscribe

What are some fun and simple puzzles or cryptography I can solve with Python to help me learn the basics?

I'm working my way through Dive Into Python for fun and I'm itching to get some enjoyable coding done. I've found, and cryptographic tasks appeal to me, but I'd appreciate some handholding if I'm stumped.

I'm not fantastic at math, so I'd enjoy string/list-based parsing, ciphering, and sorting puzzles -- especially if there's 'starter' examples and lots of interesting input sources or messages to work with. For example, coding an Enigma machine or similar mechanical cipher would be lots of fun (as long as I can look up actual implementations to compare). Are there any puzzle-y Python tutorials? Or just cryptographic tutorials not prog. language-specific (with pseudocode)?
posted by cowbellemoo to Computers & Internet (12 answers total) 14 users marked this as a favorite
Here's a puzzle from NPR Sunday Edition that I used Perl, and then C, to solve.

Take the phrase "once upon a time" written in Morse code. Change all the dots to dashes, and dashes to dots. This will spell out a new phrase. What is it?

I moved to C to speed up the dictionary lookups, and eventually printed out likely candidates and scanned through them by eye to figure out the answer.

I haven't played with Python, so I wouldn't be of help there.
posted by dr. fresh at 1:00 PM on February 28, 2008

Best answer: I don't know that they're as nicely gift-wrapped as you'd like, but there are a number of cryptographic challenges in the back of The Code Book. Python, being a general-purpose programming language, is totally viable as a tool to solve them.
posted by Netzapper at 1:03 PM on February 28, 2008

Best answer: It doesn't fit your bill fully but you might try Project Euler. Some python solutions to these problems are at pyeuler.
posted by swapspace at 1:12 PM on February 28, 2008 [1 favorite]

Best answer: There's Building Skills With Python that I had bookmarked; some of the later stuff might be interesting to you.
posted by RikiTikiTavi at 1:49 PM on February 28, 2008

Not exactly what you wanted but there are lots of interesting exercises along with skeletal code at this course website. I took this course last semester and found the exercises really fascinating and a great intro to python. They're mostly simulations dealing with non-linear systems not puzzles, but you might well find something interesting there.
posted by peacheater at 2:02 PM on February 28, 2008

What's the shortest implementation of ROT-13 you can come up with?

Write a subroutine to return the right suffix for a date, i.e. 1st, 2nd, 3rd.

Write a program to give change, specifying the exact coins and bills in the most efficient way.

Write a program to cheat at Scrabulous by finding all the possible words you can make with your letters.

Write a search engine.
posted by AmbroseChapel at 2:27 PM on February 28, 2008

Best answer: Ruby Quiz will have plenty of things for you to try. A few of them are language specific, but most should be just as fun in python as in ruby. There was also a perl quiz, though I don't know much about it other than there are 26 quizzes in the archive, so it's probably worth checking out.
posted by mrgoldenbrown at 4:17 PM on February 28, 2008

Oh yeah, the first puzzle deals with an encryption algorithm. And all the quizzes have explanations in english and several different sample solutions in ruby. You'll have to suss out the equivalent python yourself :)
posted by mrgoldenbrown at 4:24 PM on February 28, 2008

This falls more in the "cryptography" bucket than the "puzzles" one, but check out the RSA algorithm. Python's excellent support for calculations on large integers means you can, in a few dozen lines, write an encryption program that's essentially uncrackable by any entity on the planet.
posted by teraflop at 4:43 PM on February 28, 2008

Write a Soduku solver. Start with trivial puzzles and build from there. Once you have a solver, write a Soduku generator.
posted by aspo at 5:02 PM on February 28, 2008

Best answer:

Assignments 5 and 6 taught me Python.
posted by crinklebat at 6:36 PM on February 28, 2008

Response by poster: Thanks everyone! I just finished the second python challange question and boy do I feel clever. Definitely going to check out the Code Book.
posted by cowbellemoo at 12:44 PM on February 29, 2008

« Older Trying To Find Evidence Of The Wendy's Jazz Cap   |   Ghostwriter! Word. Newer »
This thread is closed to new comments.