Advertisement
cd62131

Split data and Cross tabulation

Nov 28th, 2013
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.26 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. # coding: utf-8
  3. ret = Hash.new {|hash, k| hash[k] = 0 }
  4. DATA.each_line do |line|
  5.   keys = line.split(':')
  6.   val = keys.pop.to_i
  7.   keys.each {|k| ret[k] += val }
  8. end
  9. ret.each {|k, v| puts "#{k}: #{v}" }
  10. __END__
  11. a:b:c:10
  12. a:e:20
  13. b:e:30
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement