self-documenting panagrams

Here are a couple of scripts which uses a brute-force algorithm to find self-documenting panagrams. Perhaps the best way of explaining what a 'self-documenting panagram' is, is to just show a couple:

Darren's python panagram program found this sentence which contains exactly nine 'a's, one 'b', five 'c's, four 'd's, thirty-six 'e's, eleven 'f's, three 'g's, ten 'h's, fifteen 'i's, one 'j', one 'k', three 'l's, three 'm's, twenty-nine 'n's, sixteen 'o's, four 'p's, one 'q', fifteen 'r's, thirty-one 's's, twenty-one 't's, six 'u's, four 'v's, four 'w's, six 'x's, seven 'y's, and one 'z'.

and...

Darren's ruby panagram program found this sentence which contains exactly nine 'a's, two 'b's, five 'c's, four 'd's, thirty-five 'e's, nine 'f's, three 'g's, nine 'h's, sixteen 'i's, one 'j', one 'k', two 'l's, three 'm's, twenty-seven 'n's, fourteen 'o's, three 'p's, one 'q', fifteen 'r's, thirty-four 's's, twenty-two 't's, six 'u's, six 'v's, seven 'w's, six 'x's, seven 'y's, and one 'z'.

You can count the letters if you want. The sentences are true. I first became interested in panagrams after stumbling across this file by Tanaka Tomoyuki located with other papers in the alt.fan.hofstadter and "GEB" FAQ. Mr Tomoyuki includes a script in Perl (and an unfinished one in C) which finds panagrams. These scripts are my transcription of his Perl script to Python and Ruby.

The scripts work by 'fixing' the letter count with a random number, essentially 'guessing' what the letter count may be. The sentence is built accordingly, then checked to see if it is true. If it's false, the letter count is fixed again and the loop continues...

This could go on forever, always starting from dumb random numbers for each letter, so it's lucky we can use an algorithm called 'Randomized Robisonizing' to help make more intelligent guesses. If the fixed count is equal to the real count, we use the same guess, otherwise we use a random number between our last guess and the real count. To be sure, the scripts do still need some luck, as they can find a solution in minutes or else run for days with no joy even with the same seed. The Ruby version tends to be much more prolific than the Python version. I am not sure why, I guess Ruby is just luckier. In fact the Ruby version gave me two different solutions for the same seed:

Only a fool would check that this sentence contains exactly six 'a's, one 'b', six 'c's, three 'd's, thirty-four 'e's, five 'f's, two 'g's, ten 'h's, thirteen 'i's, one 'j', two 'k's, five 'l's, one 'm', twenty-two 'n's, seventeen 'o's, one 'p', one 'q', seven 'r's, thirty-two 's's, twenty-six 't's, three 'u's, seven 'v's, eight 'w's, six 'x's, seven 'y's, and one 'z'.
Only a fool would check that this sentence contains exactly six 'a's, one 'b', six 'c's, three 'd's, thirty-three 'e's, four 'f's, two 'g's, ten 'h's, twelve 'i's, one 'j', two 'k's, six 'l's, one 'm', twenty 'n's, sixteen 'o's, one 'p', one 'q', seven 'r's, thirty-two 's's, twenty-five 't's, three 'u's, six 'v's, eight 'w's, seven 'x's, seven 'y's, and one 'z'

If you want to try for your own panagram just change the seed to what you wish. You will have to arrange the sentence yourself because the letter-count is enumerated (and therefore added to the sentence) in random order. Note that the maximum count for any one letter is 99 or the script will barf. Depending on your luck it might take a _very_ long time to find your panagram, so either run it overnight or consider 'nice'ing the task because your cpu will be pegged ;)

You can view the online panagram.py Python source code.
You can view the online panagram.rb Ruby source code.
You can download both scripts in a compressed tarball.

stats

It is Sunday May 18, 2008 9:29 am
This page served 1754 times
This page last modified: April 14, 2008 11:28 am
Your IP address is: 38.103.63.17
You are browsing using: CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
You are browsing from: United States.
badcomputer.org's uptime: 09:29:14 up 24 days, 10:11, 0 users, load average: 0.02, 0.02, 0.00

local

home | unix stuff | dir2ogg | sneetchalizer | wmainfo | q&d guide to permissions | q&d guide to tar and gzip | code | MS rant | browser shootout | linux & iAudio X5 | photos | music | programming poetry | sieve of Eratosthenes | plea | rain | suffer | archive | about | recipes | compaqr3000 | sitemap

search

Google

credits

hacker emblem

This page, and all pages on this site were created and are maintained by Darren Kirby using valid XHTML 1.0 and CSS, and are ©copyright 2002 - 2008. The Penguin image was created by Tukka, and is used by permission. Inspiration for the look of this site was provided by Eric A. Meyer's CSS gallery. This website runs on Gentoo Linux. It is served by Apache. PHP and MySQL hold together the backend.

advertisement