progs/pow.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Sun, 29 Sep 2024 18:46:02 +0100
changeset 965 94f5cce73a4f
parent 882 5fcad75ade92
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