Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active December 16, 2015 10:58
Show Gist options
  • Save joyrexus/5423644 to your computer and use it in GitHub Desktop.
Save joyrexus/5423644 to your computer and use it in GitHub Desktop.
Powerset implementations in coffeescript.
powerset = (S) ->
P = [[]]
P.push P[j].concat S[i] for j of P for i of S
P
{_} = 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