Skip to content

Instantly share code, notes, and snippets.

@rugyoga
Created May 5, 2020 21:14
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 rugyoga/9ac7507f86589c7f187e4f85b848d61e to your computer and use it in GitHub Desktop.
Save rugyoga/9ac7507f86589c7f187e4f85b848d61e to your computer and use it in GitHub Desktop.
Find the most frequently occurring alphanumeric in a very large data file
chars = Hash.new(0)
File.open("2019-annual/taxa.txt") do |f|
f.each_char.lazy.each do |char|
chars[char] += 1 if char.match(/^[[:alpha:]]$/)
end
end
puts chars.to_a.max{ |a, b| a[1] <=> b[1] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment