Skip to content

Instantly share code, notes, and snippets.

@christianp
Created February 28, 2015 20:17
Show Gist options
  • Save christianp/43845abde2c745bd1bb3 to your computer and use it in GitHub Desktop.
Save christianp/43845abde2c745bd1bb3 to your computer and use it in GitHub Desktop.
ratio of dots to dashes in Gulliver's Travels in International Morse Code - https://twitter.com/wacnt/status/566748866477694976
gulliver = open(r'c:\users\christian\downloads\gulliver.txt',encoding='utf-8').read()
letters = 'abcdefghijklmnopqrstuvwxyz1234567890'
morse = '.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. .---- ..--- ...-- ....- ..... -.... --... ---.. ----. -----'.split(' ')
dashes = {letter:code.count('-') for letter,code in zip(letters,morse)}
dots = {letter:code.count('.') for letter,code in zip(letters,morse)}
ndashes = sum(dashes.get(l,0) for l in gulliver.lower())
ndots = sum(dots.get(l,0) for l in gulliver.lower())
print(ndots/float(ndashes))
print(ndots,ndashes)
@christianp
Copy link
Author

1.5240217474538633
696577 457065

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment