Created
August 19, 2012 02:50
-
-
Save mkb/3391254 to your computer and use it in GitHub Desktop.
Anagrams
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
| #!/usr/bin/env ruby | |
| # Props to @watersb, @ussintega, and @climagic | |
| one = "Mitt Romney and Paul Ryan" | |
| two = "My ultimate Ayn Rand porn" | |
| def sorted_letters(sentence) | |
| sentence.downcase.gsub(/\s+/, '').chars.sort.join | |
| end | |
| def is_anagram?(first, second) | |
| sorted_letters(first) == sorted_letters(second) | |
| end | |
| puts is_anagram?(one, two) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment