progs/pow.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 24 Oct 2025 10:45:17 +0100
changeset 1016 3a431a78499d
parent 964 d3e22099963d
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