Created
September 14, 2019 18:28
-
-
Save linasm/3f50d8eb75b3475392c725089fc11023 to your computer and use it in GitHub Desktop.
Subset Sum using BitSet
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.collection.decorators._ // org.scala-lang.modules:scala-collection-contrib:0.2.0 | |
import scala.collection.immutable | |
import scala.util.Random | |
object SubsetSums extends App { | |
//val list = Array.fill(10000) { Random.nextInt(10000) + 1 } | |
val list = Array(2, 4, 8) | |
var sums = immutable.BitSet(0) | |
for (x <- list) sums |= sums << x | |
println(sums.mkString(" ")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment