author | Christian Urban <christian.urban@kcl.ac.uk> |
Fri, 29 Nov 2024 18:58:18 +0000 | |
changeset 975 | ae5c03560d4d |
parent 965 | 94f5cce73a4f |
permissions | -rw-r--r-- |
965 | 1 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
def concat(A: Set[String], B: Set[String]) : Set[String] = |
564 | 3 |
for (x <- A ; y <- B) yield x ++ y |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
def pow(A: Set[String], n: Int) : Set[String] = n match { |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
case 0 => Set("") |
882 | 7 |
case n => concat(A, pow(A, n - 1)) |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
|
650 | 10 |
|
11 |
||
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
val A = Set("a", "b", "c", "d") |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
val B = Set("a", "b", "c", "") |
965 | 14 |
pow(A, 4).size |
15 |
pow(B, 4).size |
|
577 | 16 |
|
17 |