Advances in Pencil Science

Saturday, December 10, 2016

Word Game

For fun, and to prove to myself that I still have coding chops after my hiatus, I put together a generalization of the game Boggle few months ago.

It's an extension to Boggle because it supports alternative rectangular grids to the standard 4x4. As published it uses the bsd unix wordlist but other wordlists can be used; this allows easy portability to other languages, though it is still hard-wired to the 26 character alphabet used in English.
The task of finding all solutions, i.e. words of arbitrary length, in a standard-sized or larger boggle array is nontrivial. Pruning the search tree is necessary, as the number of all possible sequences is immense. One version of the game that I often play on my iPhone limits solutions to 7 letter lengths, which is exasperating when you find an 8 or 9 letter word! My version does not have this limitation.
Also I have a version, a little behind the main one,  played with the Python curses library, because I can be a bit old-fashioned.
All visible here:

Work done at U Texas for ensemble management

Work done at U Texas for management of large ensembles of large scientific calculations, with robustness to job failure or resource allocation expiry, is visible here:

This is structured as a framework. The computation code and the analysis code are plugged into the framework by the end user. This is designed to be minimally intrusive. If the varied parameters of interest are already read in from a file and the code is runnable on the target machine, the user need only understand a fairly simple method for declaring the structure of the computation in ensemble parameter files.

Because the models are presumed coarse-grained (running for hours, not milliseconds) operating system calls are not costly. Consequently it is possible to wrap the executables into python objects, which makes the underlying code quite clean.

Friday, April 12, 2013


There's a serious problem with the current state of shared data - it is almost completely unusable! Here are some ideas for sharing more effectively.

Wednesday, February 29, 2012

Wednesday, January 18, 2012

Friday, August 12, 2011

Fixing Excel text exports in OS X

Excel exports .tsv and .csv with a broken linefeed character.

To fix: copy this file to ""


from sys import argv
infnam, outfnam = argv[1:]
inf = file(infnam)
indata =
outdata = ""
for ch in indata:
if ord(ch) == 13:
outdata += "\n"
outdata += ch
outf = file(outfnam,"w")

Then invoke with:

python oldfilename newfilename

Thursday, December 9, 2010


This code can count to a million in words. It could probably be refactored so it was shorter and could count to any number. If you were patient enough.

The "-b" flag puts "and" in the places a Brit would put it. It's optional but preferred.
I have random stopping points to increase the modest entertainment value of it running.

Can you recursively get wordify up to the quintillions? How should the "-b" flag be handled?

Can you do this in French?

from string import ascii_lowercase as alphabet
from sys import argv

units = [""] + "one two three four five six seven eight nine".split()
teens = "ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen".split()
tenties = 2 * [""] + "twenty thirty forty fifty sixty seventy eighty ninety".split()

def name(number,terminate = True,continued = False,brit=False):
assert type(number) == int
assert number > 0 and number < 1001
if number == 1000: return "one thousand"
hundreds,residual = divmod(number,100)
tens,ones = divmod(residual,10)
result = ""
if hundreds:
result += units[hundreds] + " hundred"
if residual and hundreds:
result += " "
if brit and residual and (hundreds or continued):
result += "and "
if (tens == 1):
result += teens[ones]
if terminate:
result += "."
if tens:
result += tenties[tens]
if ones: result += "-"
if ones:
result += units[ones]
if terminate:
result += "."
return result

def wordify(number,brit=False):
assert type(number) == int
assert number > 0 and number < 1000000
thousands,residual = divmod(number,1000)
result = ""
if thousands:
result = name(thousands,False,brit=brit) + " thousand"
if residual:
result += " "
result += name(residual,continued = True,brit=brit)
result += "."
result = name(number)
return result

if __name__ == "__main__":

from time import sleep
from random import randint

brit = "-b" in argv

sleeper = 30
for i in range(1,1000000):
if i == sleeper:
sleeper += randint(3000,90000)
print wordify(i,brit=brit)


nine hundred and ninety-nine thousand nine hundred and ninety-six.
nine hundred and ninety-nine thousand nine hundred and ninety-seven.
nine hundred and ninety-nine thousand nine hundred and ninety-eight.
nine hundred and ninety-nine thousand nine hundred and ninety-nine.

That's as far as it goes so far. Go fix it.