ruby/anagrams.rb
# take two large strings and determine the number of deletions required to make the strings anagrams.
# return the number of deletions
take two large strings and determine the number of deletions required to make the strings anagrams.
return the number of deletions
take two large strings and determine the number of deletions required to make the strings anagrams . return the number of deletions
def make_anagrams(string_one, string_two)
	changes = 0
	word_one_hash = Hash.new(0)
	word_two_hash = Hash.new(0)
	"abcdefghijklmnopqrstuvwxyz".chars.each {|c| word_one_hash[c] = 0}
	"abcdefghijklmnopqrstuvwxyz".chars.each {|c| word_two_hash[c] = 0}
	string_one.chars.each {|c| word_one_hash[c] += 1}
	string_two.chars.each {|c| word_two_hash[c] += 1}
	word_one_hash.each do |k,v| 
		if word_one_hash[k] > word_two_hash[k] 
			changes += word_one_hash[k] - word_two_hash[k] 
		else 
			changes += word_two_hash[k] - word_one_hash[k]
		end
	end
	p changes
end
def make_anagrams ( string_one , string_two ) changes = 0 word_one_hash = Hash . new ( 0 ) word_two_hash = Hash . new ( 0 ) "abcdefghijklmnopqrstuvwxyz" . chars . each { | c | word_one_hash [ c ] = 0 } "abcdefghijklmnopqrstuvwxyz" . chars . each { | c | word_two_hash [ c ] = 0 } string_one . chars . each { | c | word_one_hash [ c ] += 1 } string_two . chars . each { | c | word_two_hash [ c ] += 1 } word_one_hash . each do | k , v | if word_one_hash [ k ] > word_two_hash [ k ] changes += word_one_hash [ k ] - word_two_hash [ k ] else changes += word_two_hash [ k ] - word_one_hash [ k ] end end p changes end
take two large strings and determine the number of deletions required to make the strings anagrams.
take two large strings and determine the number of deletions required to make the strings anagrams .
# determine the shared letters between the two strings.
string_one
string_two