Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## script
- class User
- MAIL_SERVERS = 3
- def initialize(username)
- @username = username
- end
- def mail_bucket
- 1 + (@username.split(//).inject(0) {|sum, x| sum = ((sum << 3) ^ (sum >> 5)) ^ x[0] } % MAIL_SERVERS)
- end
- end
- while username = gets
- username.chomp!
- user = User.new(username)
- puts user.mail_bucket
- end
- ## results
- $ cat usernames.txt | ruby hash_test.rb | sort | uniq -c
- 1121 1
- 1146 2
- 1084 3
Add Comment
Please, Sign In to add comment