Skip to content

Instantly share code, notes, and snippets.

@alexhanh
Created January 20, 2016 11:16
Show Gist options
  • Select an option

  • Save alexhanh/75e21ce576e39c98b3da to your computer and use it in GitHub Desktop.

Select an option

Save alexhanh/75e21ce576e39c98b3da to your computer and use it in GitHub Desktop.
ENV["RAILS_ENV"] ||= "development"
require File.expand_path('../config/environment', __FILE__)
rewards = {
1000 => 1,
100 => 5,
50 => 10,
20 => 50
}
tickets = []
User.all.each do |user|
user.raffle_tickets.times do
tickets << user.email
end
end
tickets.shuffle!
final = []
rewards.each do |reward, count|
count.times do
winner = tickets.pop
tickets.delete(winner) # only 1 reward per winner
u = User.where(email: winner).first
puts "#{u.first_name} #{u.last_name[0]}. #{winner} wins #{reward}"
final << ["#{u.first_name} #{u.last_name[0]}.", reward, u.email, u.raffle_tickets]
end
end
pp final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment