Created
March 26, 2015 22:55
-
-
Save aessam/aede5480b7bf8d36a714 to your computer and use it in GitHub Desktop.
[Better and some how shouldn't be broken] Solving Anagram check problem using python and Linear Algebra and the complexity is O(n), which is 2nd lovely after constant :D
This file contains hidden or 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
| import math | |
| def stringNorm(s): | |
| odd = 0 | |
| even = 0 | |
| for c in s: | |
| if not c==" ": | |
| if ord(c)%2==0: | |
| even+=math.pow(ord(c),2) | |
| else: | |
| odd+=math.pow(ord(c),2) | |
| return math.pow(odd,2)+math.pow(even,2) | |
| def anagram_detection(s1,s2): | |
| return stringNorm(s1)==stringNorm(s2) | |
| s1 = input("Please enter first string: ").lower() | |
| s2 = input("Please enter second string: ").lower() | |
| print ("Anagram.") if anagram_detection(s1,s2) else print ("Not Anagram.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment