Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
17
Task/Power-set/Nim/power-set.nim
Normal file
17
Task/Power-set/Nim/power-set.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import sets, hashes
|
||||
|
||||
proc hash(x: HashSet[int]): Hash =
|
||||
var h = 0
|
||||
for i in x: h = h !& hash(i)
|
||||
result = !$h
|
||||
|
||||
proc powerset[T](inset: HashSet[T]): HashSet[HashSet[T]] =
|
||||
result.incl(initHashSet[T]()) # Initialized with empty set.
|
||||
for val in inset:
|
||||
let previous = result
|
||||
for aSet in previous:
|
||||
var newSet = aSet
|
||||
newSet.incl(val)
|
||||
result.incl(newSet)
|
||||
|
||||
echo powerset([1,2,3,4].toHashSet())
|
||||
Loading…
Add table
Add a link
Reference in a new issue