Skip to content

Instantly share code, notes, and snippets.

@paulkaplan
Created October 5, 2011 04:07
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 paulkaplan/1263607 to your computer and use it in GitHub Desktop.
Save paulkaplan/1263607 to your computer and use it in GitHub Desktop.
Get alphabetical histogram from census data (census.gov/genealogy/name
f = File.open("dist.all.last", 'r')
full = []
h = {}
last = 0
while( line = f.gets )
data = []
line.split(" ").each {|x| data << x}
full << data
if h[data[0][0]].is_a? Float
h[data[0][0]] += (data[2].to_f - last)
else
h[data[0][0]] = (data[2].to_f - last)
end
last = data[2].to_f
end
f.close
data = []
h.each { |key, value| data << value }
puts h.sort_by { |key, value| value }
puts h.values.reduce(0) { |sum, value| sum + value }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment