Skip to content

Instantly share code, notes, and snippets.

@RoelCastano
Last active August 29, 2015 13:57
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 RoelCastano/9691204 to your computer and use it in GitHub Desktop.
Save RoelCastano/9691204 to your computer and use it in GitHub Desktop.
# ----------------------------------------------------- #
# Roel Castaño Moreno. #
# March 21, 2014. #
# Problem 1 for Icalia Labs. #
# ----------------------------------------------------- #
# Asks for user's input (sentence to be processed).
print "Please write a sentence: "
sentence = gets.chomp
# Downcases the user's input and splits it into an array.
arrayWords = sentence.downcase!.split
# Creates a hash were the values of the array are stored.
# If the word already exists in the hash, the value is incremented by 1.
list = Hash.new(0)
arrayWords.each do |i|
list[i] += 1
end
# Outputs each of the words in the hash and its respective count.
list.each do |word, count|
puts word + " = " + count.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment