-
-
Save techsin/9e5d0b13539ed8c23496 to your computer and use it in GitHub Desktop.
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
sentence = <<-something | |
Steven likes the movies. Blake likes to ride his bike but hates movies. | |
Blake is taller than than than steven. Steven Steven is a great teacher. | |
something | |
counter = Hash.new(0) | |
sentence.gsub!(".","").split(" ").each do |word| | |
counter[word] += 1 | |
end | |
words = counter.select { |k,v| v>2 } | |
cost = {} | |
("a".."z").each_with_index { |x,i| cost[x] = i+1 } | |
def getCost(words, cost) | |
h = {} | |
words.each do |k,v| | |
sum = 0 | |
k.split('').each do |l| | |
sum += cost[l.downcase] | |
end | |
h[k] = sum * v | |
end | |
h | |
end | |
puts getCost(words, cost) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment