Skip to content

Instantly share code, notes, and snippets.

@masarakki
Created September 4, 2012 11:57
Show Gist options
  • Save masarakki/3620586 to your computer and use it in GitHub Desktop.
Save masarakki/3620586 to your computer and use it in GitHub Desktop.
ある集合の長さnの直積集合を求める
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