Created
December 31, 2017 02:09
-
-
Save ijunaid8989/1d4541fbdf5e198636affe45cdd3b72f to your computer and use it in GitHub Desktop.
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
module Enumerable # or require 'facets/enumerable/frequency' | |
def frequency | |
each_with_object(Hash.new(0)) { |item, counter| counter[item] += 1 } | |
end | |
end | |
def anagrams?(s1, s2) | |
frequency = proc { |s| s.gsub(/\s+/, "").downcase.chars.frequency } | |
frequency.(s1) == frequency.(s2) | |
end | |
if ARGV.size != 2 | |
$stderr.puts("Need two words") | |
exit(1) | |
elsif anagrams?(*ARGV) | |
puts("Anagrams") | |
else | |
puts("Not anagrams") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment