| author | Christian Urban <urbanc@in.tum.de> |
| Mon, 03 Apr 2017 01:10:54 +0800 | |
| changeset 482 | 74149519e436 |
| parent 471 | e5df48ff7033 |
| child 525 | e5a004ffa681 |
| 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