Skip to content

Instantly share code, notes, and snippets.

@gdiggs
Created September 2, 2010 00:04
Show Gist options
  • Save gdiggs/561608 to your computer and use it in GitHub Desktop.
Save gdiggs/561608 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# Assassin - Random and fair pairing for a game of assassin of any size (defaults to 10)
# Takes number of players from args
num_players = ARGV[0].to_i == 0 ? 10 : ARGV[0].to_i
killers = (0..num_players-1).to_a
targets = killers.shuffle
puts "killers: #{killers.inspect}"
puts "targets: #{targets.inspect}"
killers.each do |killer|
target = targets[killer]
if killer == targets[killer]
puts "#{killer} has him/herself"
elsif targets.index(killer) == target
puts "#{killer} has #{target} and #{target} has #{killer}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment