Sha256: ceb15e6f664a9448026051b7f4d43b2c42c31ce0f4cb3e033efdb0b581450e8b
Contents?: true
Size: 466 Bytes
Versions: 18
Compression:
Stored size: 466 Bytes
Contents
require 'set' class Set def power_set if empty? Set[ self ] else any_value = [to_a.first] subsubs = (self - any_value).power_set subsubs + subsubs.map{ |subset| subset + any_value } end end end class Array def power_set if empty? [self] else subset = dup value = [ subset.pop ] subsubs = subset.power_set subsubs.concat( subsubs.map{ |subset| subset + value } ) end end end
Version data entries
18 entries across 18 versions & 2 rubygems