Skip to content

Instantly share code, notes, and snippets.

@danielbonnell
Last active August 29, 2015 14:08
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 danielbonnell/6bc396be106572597cee to your computer and use it in GitHub Desktop.
Save danielbonnell/6bc396be106572597cee to your computer and use it in GitHub Desktop.
Shakespeare Challenge
def word_frequency(sample_file)
count = Hash.new(0)
IO.readlines(sample_file).each do |line|
line.split(/[\W\s]/).each do |word|
count[word.downcase] += 1
end
end
count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment