Variations on Nishimotoさん's Disco challenge.
-
-
Save jmettraux/1308c411c74f8429ed4447d8fe0d55ad 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
# brutal: reads the whole file into memory | |
require 'pp' | |
pp File.read('names.txt') | |
.each_char | |
.inject(Hash.new(0)) { |h, c| | |
c = c.downcase | |
h[c] += 1 if c >= 'a' && c <= 'z' | |
h } | |
.sort_by { |k, v| -v } |
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
# only loads 1024 chars max | |
require 'pp' | |
h = Hash.new(0) | |
File.open('names.txt') do |f| | |
loop do | |
s = f.read(1024); break unless s | |
s.each_char { |c| | |
c = c.downcase | |
h[c] += 1 if c >= 'a' && c <= 'z' } | |
end | |
end | |
pp h.sort_by { |k, v| -v } |
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
sato amano nishida saito fujiwara matsudaira | |
nishimoto ishibashi takata kitadai mitsuda bussaki himura | |
kikuchi maru arai ishikawa | |
takahashi ueda |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment