Created
July 31, 2023 17:30
-
-
Save exegeteio/8d3b781cb5809d9ecda703521a053a0e to your computer and use it in GitHub Desktop.
Cassidoo Anagram Detector
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
#!/usr/bin/env ruby | |
def anagram?(subject, test) | |
(test.downcase.chars - subject.downcase.chars).none? | |
end | |
tests = { | |
'evil' => 'vile', | |
'a gentleman' => 'elegant man', | |
'Santa' => 'Satan', | |
'William Shakespeare' => 'I am a weakish speller', | |
'Tom Marvolo Riddle' => 'I am Lord Voldemort', | |
'race' => 'racer', # Valid with multuples of letters from the subject. | |
'racer' => 'race', # Valid with only a single copy of each letter. | |
'force' => 'farce' | |
} | |
tests.each do |s, t| | |
puts "#{anagram?(s, t) ? 'true ' : 'false'} #{s} => #{t}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment