Power set: Difference between revisions
Content added Content deleted
Line 2,412: | Line 2,412: | ||
Set(2, 3), Set(2, 4), Set(3, 4), Set(1, 2, 3), Set(1, 3, 4), Set(1, 2, 4), Set(2, 3, 4), Set(1, 2, 3, 4))) |
Set(2, 3), Set(2, 4), Set(3, 4), Set(1, 2, 3), Set(1, 3, 4), Set(1, 2, 4), Set(2, 3, 4), Set(1, 2, 3, 4))) |
||
println(s"Successfully completed without errors. [total ${currentTime - executionStart} ms]") |
println(s"Successfully completed without errors. [total ${currentTime - executionStart} ms]") |
||
⚫ | |||
}</lang> |
|||
⚫ | |||
<lang scala>def powerset[A](s: Set[A]) = (0 to s.size).map(s.toSeq.combinations(_)).reduce(_ ++ _).map(_.toSet)</lang> |
<lang scala>def powerset[A](s: Set[A]) = (0 to s.size).map(s.toSeq.combinations(_)).reduce(_ ++ _).map(_.toSet)</lang> |
||