Skip to content

Instantly share code, notes, and snippets.

@dschuetz
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dschuetz/5b210336be091486124e to your computer and use it in GitHub Desktop.
Save dschuetz/5b210336be091486124e to your computer and use it in GitHub Desktop.
Simple scoring routine for ascii text. Uses Moby Dick as a source for ascii frequencies (only chars 32-127).
ASCII_FREQS = [
162.7, 1.5, 2.6, 0.0, 0.0, 0.0, 0.0, 2.4,
0.2, 0.2, 0.1, 0.0, 16.0, 5.0, 6.5, 0.0,
0.1, 0.2, 0.1, 0.0, 0.0, 0.1, 0.0, 0.1,
0.1, 0.0, 0.2, 3.4, 0.0, 0.0, 0.0, 0.8,
0.0, 2.2, 1.2, 1.0, 0.7, 1.1, 0.7, 0.6,
1.2, 3.0, 0.2, 0.2, 0.8, 0.6, 1.0, 0.9,
1.0, 0.3, 0.7, 1.9, 2.1, 0.2, 0.1, 1.1,
0.0, 0.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 62.8, 12.9, 18.1, 31.3, 97.0, 16.8, 16.9,
51.1, 51.9, 0.8, 6.6, 34.9, 18.9, 53.9, 57.4,
13.6, 1.0, 43.2, 51.7, 71.7, 22.2, 7.0, 17.5,
0.9, 13.9, 0.5, 0.0, 0.0, 0.0, 0.0
]
def score(s):
score = 0
for ch in s:
if ord(ch) > 31 and ord(ch) < 127:
score += ASCII_FREQS[ord(ch)-32]/100
return score
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment