Skip to content

Instantly share code, notes, and snippets.

@ucarion
Created May 20, 2014 04:33
Show Gist options
  • Save ucarion/dd6d390956a4fa118279 to your computer and use it in GitHub Desktop.
Save ucarion/dd6d390956a4fa118279 to your computer and use it in GitHub Desktop.
Random-sorting 8-groups
people = (0...8).to_a
tries = 10_000_000
count = 0
tries.times do
if people.shuffle.each_with_index.all? { |person, index| person != index }
count += 1
end
end
p count.to_f / tries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment