Created
January 14, 2015 02:41
-
-
Save dorwardv/0f11e83475389f1d4051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dorwardv@Raistlin:~/projects/personal/python/is_anagram$ python anagram.py "A telephone girl" "Repeating 'Hello'" | |
array('i', [1, 0, 0, 0, 3, 0, 1, 1, 1, 0, 0, 2, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0]) | |
array('i', [1, 0, 0, 0, 3, 0, 1, 1, 1, 0, 0, 2, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0]) | |
True | |
dorwardv@Raistlin:~/projects/personal/python/is_anagram$ python anagram.py "The United States Bureau of Fisheries" "I Raise the Bass to Feed Us in the Future" | |
array('i', [2, 1, 0, 1, 6, 2, 0, 2, 3, 0, 0, 0, 0, 1, 1, 0, 0, 2, 4, 4, 3, 0, 0, 0, 0, 0]) | |
array('i', [2, 1, 0, 1, 6, 2, 0, 2, 3, 0, 0, 0, 0, 1, 1, 0, 0, 2, 4, 4, 3, 0, 0, 0, 0, 0]) | |
True | |
dorwardv@Raistlin:~/projects/personal/python/is_anagram$ python anagram.py "Just because some of us can read and write and do a little math, that doesn't mean we deserve to conquer the universe." "Just because some of us can read and write and do a little math, that doesn't mean we deserve to conquer the universe." | |
array('i', [9, 1, 3, 6, 16, 1, 0, 3, 3, 1, 0, 2, 3, 7, 6, 0, 1, 5, 7, 10, 5, 2, 2, 0, 0, 0]) | |
array('i', [9, 1, 3, 6, 16, 1, 0, 3, 3, 1, 0, 2, 3, 7, 6, 0, 1, 5, 7, 10, 5, 2, 2, 0, 0, 0]) | |
True | |
dorwardv@Raistlin:~/projects/personal/python/is_anagram$ python anagram.py "Mr. William Jefferson Clinton, former President of these United States of America" "Monica flirts. Wife sees hot jism from cad land on fat intern, set to rule free empire" | |
array('i', [4, 0, 2, 2, 10, 5, 0, 1, 6, 1, 0, 3, 4, 5, 5, 1, 0, 6, 5, 6, 1, 0, 1, 0, 0, 0]) | |
array('i', [4, 0, 2, 2, 10, 5, 0, 1, 6, 1, 0, 3, 4, 5, 5, 1, 0, 6, 5, 6, 1, 0, 1, 0, 0, 0]) | |
True | |
dorwardv@Raistlin:~/projects/personal/python/is_anagram$ python anagram.py "Snooze Alarms" "Alas! No More Z's" | |
array('i', [2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 1]) | |
array('i', [2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 1]) | |
True | |
dorwardv@Raistlin:~/projects/personal/python/is_anagram$ cat anagram.py | |
import sys | |
import array | |
def populate_letter_count(arr,str): | |
for i in range(len(str)): | |
index = ord(str[i]) - ord('A') | |
if ( index < 26) and (index >=0): | |
arr[index] = arr[index] + 1 | |
continue | |
index = ord(str[i]) - ord('a') | |
if ( index < 26) and (index >=0): | |
arr[index] = arr[index] + 1 | |
continue | |
continue | |
s1 = array.array('i',(0 for i in range(0,26))) | |
s2 = array.array('i',(0 for i in range(0,26))) | |
str1 = sys.argv[1] | |
str2 = sys.argv[2] | |
populate_letter_count(s1,str1) | |
populate_letter_count(s2,str2) | |
print s1 | |
print s2 | |
print s1 == s2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment