Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
9
Task/Power-set/Scala/power-set-1.scala
Normal file
9
Task/Power-set/Scala/power-set-1.scala
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import scala.compat.Platform.currentTime
|
||||
|
||||
object Powerset extends App {
|
||||
def powerset[A](s: Set[A]) = s.foldLeft(Set(Set.empty[A])) { case (ss, el) => ss ++ ss.map(_ + el)}
|
||||
|
||||
assert(powerset(Set(1, 2, 3, 4)) == Set(Set.empty, Set(1), Set(2), Set(3), Set(4), Set(1, 2), Set(1, 3), Set(1, 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]")
|
||||
}
|
||||
1
Task/Power-set/Scala/power-set-2.scala
Normal file
1
Task/Power-set/Scala/power-set-2.scala
Normal file
|
|
@ -0,0 +1 @@
|
|||
def powerset[A](s: Set[A]) = (0 to s.size).map(s.toSeq.combinations(_)).reduce(_ ++ _).map(_.toSet)
|
||||
|
|
@ -1 +0,0 @@
|
|||
def powerset[A](s: Set[A]) = s.foldLeft(Set(Set.empty[A])) { case (ss, el) => ss ++ ss.map(_ + el) }
|
||||
Loading…
Add table
Add a link
Reference in a new issue