Skip to content

Instantly share code, notes, and snippets.


jmettraux/ Secret

Created Jul 13, 2017
What would you like to do?


Variations on Nishimotoさん's Disco challenge.

# brutal: reads the whole file into memory
require 'pp'
.inject( { |h, c|
c = c.downcase
h[c] += 1 if c >= 'a' && c <= 'z'
h }
.sort_by { |k, v| -v }
# only loads 1024 chars max
require 'pp'
h ='names.txt') do |f|
loop do
s =; break unless s
s.each_char { |c|
c = c.downcase
h[c] += 1 if c >= 'a' && c <= 'z' }
pp h.sort_by { |k, v| -v }
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
You can’t perform that action at this time.