Created
September 4, 2012 11:57
-
-
Save masarakki/3620586 to your computer and use it in GitHub Desktop.
ある集合の長さnの直積集合を求める
This file contains hidden or 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 **(num) | |
args = [] | |
(num - 1).times { args << self } | |
product(*args) | |
end | |
end | |
[0,1] ** 3 #=> [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment