Power set: Difference between revisions

Updated to Nim 1.4: changed initSet to initHashSet, to Set to toHashSet. Also changed some variable names and some other things.
m (→‎{{header|Wren}}: Correction to preamble.)
(Updated to Nim 1.4: changed initSet to initHashSet, to Set to toHashSet. Also changed some variable names and some other things.)
Line 2,401:
=={{header|Nim}}==
<lang nim>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]): autoHashSet[HashSet[T]] =
result = toSet.incl([initSetinitHashSet[T]()]) # Initialized with empty set.
for ival in inset:
 
let previous = result
for i in inset:
varfor tmpaSet =in resultprevious:
for j invar result:newSet = aSet
var k = jnewSet.incl(val)
kresult.incl(inewSet)
tmp.incl(k)
echo powerset(toSet([1,2,3,4].toHashSet())</lang>
result = tmp
 
echo powerset(toSet([1,2,3,4]))</lang>
 
=={{header|Objective-C}}==
Anonymous user