progs/pow.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 29 Nov 2024 18:59:32 +0000
changeset 976 e9eac62928f5
parent 965 94f5cce73a4f
permissions -rw-r--r--
updated


def concat(A: Set[String], B: Set[String]) : Set[String] =
  for (x <- A ; y <- B) yield x ++ y

def pow(A: Set[String], n: Int) : Set[String] = n match {
  case 0 => Set("")
  case n => concat(A, pow(A, n - 1))
}



val A = Set("a", "b", "c", "d")
val B = Set("a", "b", "c", "")
pow(A, 4).size
pow(B, 4).size