Skip to content

Instantly share code, notes, and snippets.

def parts(a: Int, x: Int, max: Int): Seq[Seq[Int]] = {
if (a == 0) {
Seq(Stream.fill(x)(0))
} else if (x == 1) {
Seq(Seq(a))
} else {
for {
i <- 1 to math.min(a, max)
s <- parts(a-i, x-1, max)
} yield (s :+ i)