Created
September 11, 2013 17:57
-
-
Save joshteng/6527309 to your computer and use it in GitHub Desktop.
SUTD SEPT 2013
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
# The method should be symmetric, i.e., | |
# is_anagram?(word1, word2) == is_anagram?(word2, word1) for any two words | |
is_anagram?('cinema', 'iceman') # => true | |
is_anagram?('iceman', 'cinema') # => true | |
# Pedantically, a word is always an anagram of itself. | |
# This is called being "reflexive," i.e., is_anagram?(word, word) == true for any word | |
is_anagram?('pants', 'pants') # => true | |
# is_anagram? should be case-insensitive | |
is_anagram?('CiNemA', 'iceman') # => true | |
# Notice: acres, cares, and scare are all anagrams of each other | |
is_anagram?('acres', 'cares') # => true | |
is_anagram?('cares', 'scare') # => true | |
is_anagram?('scare', 'acres') # => true | |
# The "words" don't need to be valid English words | |
is_anagram('abcde2', 'c2abed') # => true | |
is_anagram?('pants', 'turtle') # => false | |
is_anagram?('123123', 'kjhasd') # => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment