Power set: Difference between revisions
Content added Content deleted
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: | Line 2,401: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
<lang nim>import sets, hashes |
<lang nim>import sets, hashes |
||
proc hash(x: HashSet[int]): Hash = |
proc hash(x: HashSet[int]): Hash = |
||
var h = 0 |
var h = 0 |
||
for i in x: h = h !& hash(i) |
for i in x: h = h !& hash(i) |
||
result = !$h |
result = !$h |
||
proc powerset[T](inset: HashSet[T]): |
proc powerset[T](inset: HashSet[T]): HashSet[HashSet[T]] = |
||
result |
result.incl(initHashSet[T]()) # Initialized with empty set. |
||
⚫ | |||
let previous = result |
|||
⚫ | |||
for aSet in previous: |
|||
var newSet = aSet |
|||
newSet.incl(val) |
|||
result.incl(newSet) |
|||
tmp.incl(k) |
|||
⚫ | |||
result = tmp |
|||
⚫ | |||
=={{header|Objective-C}}== |
=={{header|Objective-C}}== |