Skip to content

Instantly share code, notes, and snippets.

@suchi
Created December 12, 2014 06:31
Show Gist options
  • Save suchi/9c7e1d30cc07eb2a8dbb to your computer and use it in GitHub Desktop.
Save suchi/9c7e1d30cc07eb2a8dbb to your computer and use it in GitHub Desktop.
プレゼント交換のペアを決める #hmrb
class Array
def xshuffle
a = (0...size).to_a
a.shuffle!
ret = Array.new(size)
(0...size).each do |ii|
ret[a[ii]] = self[a[(ii + 1) % size]]
end
ret
end
end
# %w{alice brian crossby david}.xshuffle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment