Created
December 12, 2014 06:31
-
-
Save suchi/9c7e1d30cc07eb2a8dbb to your computer and use it in GitHub Desktop.
プレゼント交換のペアを決める #hmrb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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