Skip to content

Instantly share code, notes, and snippets.

@linasm
Created September 14, 2019 18:28
Show Gist options
  • Save linasm/3f50d8eb75b3475392c725089fc11023 to your computer and use it in GitHub Desktop.
Save linasm/3f50d8eb75b3475392c725089fc11023 to your computer and use it in GitHub Desktop.
Subset Sum using BitSet
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