in Hacks

Things of interest: Calculators

531-8008 by minusbaby

What have bliss, googol, eggshell and oilhole in common? Think of your days in school where you got your first calculator. Right, you can write these words with it.
I asked myself in these days: “How many words can you write on it? And which are they?”
While I was browsing on Flickr for a picture with data and numbers I saw one with these “calculator words”. So, I decided to write a program to find them. This program is written in Python and uses the two megabytes (it’s small) NetBSD word list.

words = open("/usr/share/dict/words").readlines()

def is_good(char):
   chars = ['b', 'e', 'g', 'h', 'i', 'l', 'o', 's']
   if char not in chars:
       return False
   return True

def bad_word(word):
    for char in word:
       if is_good(char) == False:
           return True
    return False


for word in words:
    word = word[:-1] # strip "n"
    if bad_word(word) == False:
        print word

Together with this program I created a list which contains words which are writable on a calculator and theirs encodings in digits.

def to_digit(char):
    table = {'o': '0',
             'i': '1',
             'e': '3',
             'h': '4',
             's': '5',
             'g': '6',
             'l': '7',
             'b': '8'}
    return table[char]

def to_calc_word(word):
    out = []
    for char in word:
        out.append(to_digit(char))
    out.reverse()
    return "".join(out)

Write a Comment

Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.