The legendary Stephen Fry recently announced a competition on his twitter feed to celebrate his 50,000th follower:
L=50 in Roman. The best tweet containing exactly 50 Ls will win. All tweets to contain the tag #L and none to exceed 140 character limit SF
Well, this sounded like fun! I decided to have a go.
A tweet containing “#L” has only 137 characters left for actual text, as there needs to be a space (or some other punctuation) after the “#L”. 50 Ls is a lot to get into that small amount of space in English.
I decided to use Python to help out.
First of all, I defined a function called L-density. This is the ratio of the number of Ls to the number of characters. To make the numbers easier to deal with (i.e. > 1) I inverted the definition so L-density becomes the ratio of the number of characters to the number of Ls. (Technically, I suppose it should be called L-sparseness, but that sounds ugly.)
The L-density required for the whole message is 137/50 = 2.74.
The L-density can also be applied to each word in the message. We want to choose words which ideally have an L-density < 2.74. In fact, as low as possible, so we can use the odd filler word (e.g. and, if, or) or bit of punctuation which uses up much needed space for Ls.
As each word requires a space or punctuation separator from the next word, we need to add one to the letter count of the word to get a useful measure of L-density. So the L-density of a word is defined as (number of characters + 1) / (number of Ls).
I wanted all English words with an L-density <= 2.74.
I grabbed a list of English words, and removed all words that do not contain ‘L’ at all.
Then I wrote a little Python script to calculate the L-density for each word, and output a list of the words in L-density order (starting with the most L-heavy words). It doesn’t bother printing out any word with an L-density > 2.74.
import sys
def sortfunc(a,b):
if words[a] < words[b]:
return -1
elif words[a] > words[b]:
return 1
else:
return 0
f = open('w.txt','r')
file = f.readlines()
words={}
for line in file:
line=line.rstrip()
length=len(line)+1 # +1 to account for space between words; short words are less use to us
lcount=line.count('L')
ldensity=1.0*length/lcount
if ldensity <= 2.74:
words[line] = ldensity
keys=words.keys()
keys.sort(sortfunc)
last=0
for key in keys:
if words[key]<>last:
print '-------------------------'
last=words[key]
print key
I ran this script on w.txt (my list of English words), and the output was:
LILL
LULL
LALL
LOLL
————————-
LULLS
LALLS
ILL
LILLS
ELL
ALL
ALLYL
LOLLS
LOLLY
ALLEL
————————-
BELLPULL
PELLMELL
LOBLOLLY
————————-
TALLOL
HALLAL[etc.]
The horizontal lines separate batches of words with the same L-density.
The most L-heavy words are at the top of the list, so it makes sense to pick words from there if possible.
Now I needed a way to quickly check my composition as I wrote it. Another Python script came to the rescue:
import sys
f = open('try','r')
file = f.readlines()
for line in file:
length=len(line)
lcount=line.count('L') +line.count('l')
print 'L count =',lcount
print 'Length =',length
print 'L-density =',1.0*length/lcount
All I had to to was open a text file called ‘try’, and check it by running this script whenever I wanted to see how I was doing. I was aiming for an L-count of 50, a length <= 137. While building up the composition, I had to aim to keep the L-density < 2.74, otherwise the first part would be L-sparse and I’d need to pick particularly L-dense words in the later part to make up the average.
This made the whole job a lot easier, as I could concentrate on picking the right words, and trying to weave a simplistic (but vaguely sensible) narrative into an SMS sized message.
I’m not claiming great literary merit for this, by the way. I’m better at code than I am at English composition (even bizarrely limited English composition). But it was fun creating simple tools to aid in the quest.
And here’s the result. Let’s see what Mr Fry thinks!
#L Lola hillbilly lolls @ mall mulls Lulu doll: fulfill illegally! Lull Jill 2 alley; kill Jill! Lily sell doll 2 Lola 4 Jill’s lolly. Gall!
UPDATE 2009-02-02: What fun! My entry didn’t win, but Stephen did call me ’smart’ when he saw this. (Contrary to popular belief, this was not shortly followed by the word ‘arse’.) The actual winner was rather good, though my favorite was the second place by @fiskerton:
Tetris v0.1 proved too easy: L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L
Recent Comments