Skip to content

Instantly share code, notes, and snippets.

@gorakhargosh
Created May 13, 2016 17:47
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 gorakhargosh/06c137a6aa1524ffe828866f3736c5c2 to your computer and use it in GitHub Desktop.
Save gorakhargosh/06c137a6aa1524ffe828866f3736c5c2 to your computer and use it in GitHub Desktop.
digital root god names
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import collections
letter_map = {
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
"f": 6,
"g": 7,
"h": 8,
"i": 9,
"j": 10,
"k": 11,
"l": 12,
"m": 13,
"n": 14,
"o": 15,
"p": 16,
"q": 17,
"r": 18,
"s": 19,
"t": 20,
"u": 21,
"v": 22,
"w": 23,
"x": 24,
"y": 25,
"z": 26,
}
def digital_root(n):
if n < 10 :
return n
x = n % 10 + digital_root(n//10)
if x < 10:
return x
else:
return digital_root(x)
def alnum_root(s):
return digital_root(sum([letter_map.get(c.lower(), 0) for c in s]))
def bucket_words(words_file):
d = collections.defaultdict(list)
with open(words_file, 'rb') as f:
words = f.readlines()
for word in words:
word = word.strip()
d[alnum_root(word)].append(word)
return d
if __name__ == '__main__':
# for word in bucket_words('/usr/share/dict/words').get(9, None):
# print word
# print bucket_words('/usr/share/dict/words').get(9, None)
cases = [
'ShreeKrishna',
'Mohammed',
'Mahavir',
'GuruNanak',
'Zarathustra',
'Gautam',
'EsaMessiah',
'Shiva',
'Brahma',
'Vishnu',
'Ganapati',
'Saraswati',
'Durga',
'Jesus',
'Allah',
'Lakshmi',
'Laxmi',
'Indra',
'Surya',
'Agni',
'Hanuman',
]
for c in cases:
print c, alnum_root(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment