author | Christian Urban <urbanc@in.tum.de> |
Fri, 28 Apr 2017 11:01:25 +0100 | |
changeset 487 | a697421eaa04 |
parent 471 | 9476086849ad |
child 525 | a2ee4b11c976 |
permissions | -rw-r--r-- |
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") pow(A, 4).size // -> 256 val B = Set("a", "b", "c", "") pow(B, 4).size // -> 121 val B2 = Set("a", "b", "c", "") pow(B2, 3).size // -> 40 val C = Set("a", "b", "") pow(C, 2) pow(C, 2).size // -> 7 pow(C, 3) pow(C, 3).size // -> 15