2016-12-05 23:44:36 +01:00
|
|
|
import sets, hashes
|
|
|
|
|
|
2019-09-12 10:33:56 -07:00
|
|
|
proc hash(x: HashSet[int]): Hash =
|
2016-12-05 23:44:36 +01:00
|
|
|
var h = 0
|
|
|
|
|
for i in x: h = h !& hash(i)
|
|
|
|
|
result = !$h
|
|
|
|
|
|
|
|
|
|
proc powerset[T](inset: HashSet[T]): auto =
|
|
|
|
|
result = toSet([initSet[T]()])
|
|
|
|
|
|
|
|
|
|
for i in inset:
|
|
|
|
|
var tmp = result
|
|
|
|
|
for j in result:
|
|
|
|
|
var k = j
|
|
|
|
|
k.incl(i)
|
|
|
|
|
tmp.incl(k)
|
|
|
|
|
result = tmp
|
|
|
|
|
|
|
|
|
|
echo powerset(toSet([1,2,3,4]))
|