Created
July 16, 2020 15:20
-
-
Save meysampg/eb3bf9a1e68168824dc6083e093a8585 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.annotation.tailrec | |
val a = List(1, 2, 3, 4) | |
@tailrec | |
def powerset(current: List[List[Int]], given: List[Int]): List[List[Int]] = given match { | |
case Nil => current | |
case head :: tail => powerset(current ++ (current map {x => head::x}), tail) | |
} | |
for (i <- powerset(List(Nil), a)) { | |
println(i) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment