Created
February 3, 2012 22:18
-
-
Save noonat/1733255 to your computer and use it in GitHub Desktop.
Power sets
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
| powerSet = (set) -> | |
| p = [[]] | |
| for val in set | |
| for i in [0...p.length] | |
| p[p.length] = p[i].concat([val]) | |
| p |
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
| var powerSet = function(set) { | |
| var p = [[]]; | |
| for (var i = 0, il = set.length; i < il; ++i) { | |
| var val = set[i]; | |
| for (var j = 0, jl = p.length; j < jl; ++j) { | |
| p[p.length] = p[j].concat([val]) | |
| } | |
| } | |
| return p; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment