Skip to content

Instantly share code, notes, and snippets.

@techsin
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techsin/9e5d0b13539ed8c23496 to your computer and use it in GitHub Desktop.
Save techsin/9e5d0b13539ed8c23496 to your computer and use it in GitHub Desktop.
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