I was even showing it around to my friends at work. They didn't notice too! Maybe this algorithm could be used for something else. But I have no fucking clue where :D
Of course I learned a lot, but still, feel a bit stupid. Do not overdo and read more - that is the lesson of today!
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
def cartprod(*args) | |
result = [[]] | |
while [] != args | |
t, result = result, [] | |
b, *args = args | |
t.each do |a| | |
b.each do |n| | |
result << a + [n] | |
end | |
end | |
end | |
result | |
end | |
# Posted here http://www.ruby-forum.com/topic/95519 |
Ou programming... my dear...
No comments:
Post a Comment