Skip to content

Instantly share code, notes, and snippets.

@rec
Last active December 20, 2015 21:09
Show Gist options
  • Save rec/6195634 to your computer and use it in GitHub Desktop.
Save rec/6195634 to your computer and use it in GitHub Desktop.
How many extra keypresses on an old-style cell phone keyboard?
# How many extra keypresses does it take to type alphabetic characters on an
# old-style cell phone keyboard?
# https://www.facebook.com/zorikh.lequidre/posts/10151583168686662
# The result: 1.14908 extra keypresses "wasted" each time!
# Frequency table from here: http://en.wikipedia.org/wiki/Letter_frequency
frequencies = {
'a': 0.08167,
'b': 0.01492,
'c': 0.02782,
'd': 0.04253,
'e': 0.12702,
'f': 0.02228,
'g': 0.02015,
'h': 0.06094,
'i': 0.06966,
'j': 0.00153,
'k': 0.00772,
'l': 0.04025,
'm': 0.02406,
'n': 0.06749,
'o': 0.07507,
'p': 0.01929,
'q': 0.00095,
'r': 0.05987,
's': 0.06327,
't': 0.09056,
'u': 0.02758,
'v': 0.00978,
'w': 0.02360,
'x': 0.00150,
'y': 0.01974,
'z': 0.00074,
}
keypresses = {
'a': 1,
'b': 2,
'c': 3,
'd': 1,
'e': 2,
'f': 3,
'g': 1,
'h': 2,
'i': 3,
'j': 1,
'k': 2,
'l': 3,
'm': 1,
'n': 2,
'o': 3,
'p': 1,
'q': 2,
'r': 3,
's': 4,
't': 1,
'u': 2,
'v': 3,
'w': 1,
'x': 2,
'y': 3,
'z': 4,
}
keypresses = sum(frequencies[key] * presses for (key, presses) in keypresses.items())
print 'Extra keypresses = %s' % (keypresses - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment