Last active
December 16, 2015 10:58
-
-
Save joyrexus/5423644 to your computer and use it in GitHub Desktop.
Powerset implementations in coffeescript.
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
powerset = (S) -> | |
P = [[]] | |
P.push P[j].concat S[i] for j of P for i of S | |
P |
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
{_} = require 'underscore' | |
powerset = (set) -> | |
f = (memo, x) -> | |
memo.concat _.map memo, (y) -> y.concat x | |
_.reduce set, f, [[]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment