Advertisement
koy

hash

koy
Aug 17th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.51 KB | None | 0 0
  1. Encoding.default_external = 'utf-8'
  2. Encoding.default_internal = 'utf-8'
  3. path = ARGV.first
  4. # ids = [1, 3 ...]
  5.  
  6. map = Hash.new
  7.  
  8. def get_user_id(line)
  9.   return (line.match /\d*$/).to_s
  10. end
  11.  
  12. File.open(path, "r") do |f|
  13.   f.each_line do |line|
  14.     id = get_user_id(line)
  15.     next if id.to_i == 0
  16.     # next if id.to_i == 0 or not ids.include? id
  17.     map[id] = Array.new if map[id].nil?
  18.     map[id].push line
  19.     puts "id: #{id}, length: #{map[id].length}" if map[id].length > 100
  20.   end
  21. end
  22.  
  23. puts map[34428]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement