🏣 Clean up for arxiv

This commit is contained in:
Mia von Steinkirch 2020-03-04 17:47:53 -08:00
parent 1b969e7db3
commit 41756cb10c
280 changed files with 2 additions and 11 deletions

View file

@ -0,0 +1,51 @@
#!/usr/bin/env python
__author__ = "bt3"
from collections import Counter
def is_anagram(s1, s2):
'''
>>> is_anagram('cat', 'tac')
True
>>> is_anagram('cat', 'hat')
False
'''
counter = Counter()
for c in s1:
counter[c] += 1
for c in s2:
counter[c] -= 1
for i in counter.values():
if i:
return False
return True
''' verify if words are anagrams by comparing a sum of Unicode code
point of the character'''
def get_unicode_sum(word):
s = 0
for p in word:
s += ord(p)
return s
def is_anagram2(word1, word2):
'''
>>> is_anagram2('cat', 'tac')
True
>>> is_anagram2('cat', 'hat')
False
'''
return get_unicode_sum(word1) == get_unicode_sum(word2)
if __name__ == '__main__':
import doctest
doctest.testmod()