author | Christian Urban <urbanc@in.tum.de> |
Sun, 28 Jul 2019 01:00:41 +0100 | |
changeset 623 | 47a299e7010f |
parent 618 | f4818c95a32e |
child 638 | 0367aa7c764b |
permissions | -rw-r--r-- |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
def concat(A: Set[String], B: Set[String]) : Set[String] = |
564 | 2 |
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
|
3 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
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
|
5 |
case 0 => Set("") |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
case n => concat(A, pow(A, n- 1)) |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
} |
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 |
val A = Set("a", "b", "c", "d") |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
pow(A, 4).size // -> 256 |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
val B = Set("a", "b", "c", "") |
572 | 13 |
pow(B, 4) |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
pow(B, 4).size // -> 121 |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
|
471 | 16 |
|
17 |
||
397
cf3ca219c727
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
18 |
val B2 = Set("a", "b", "c", "") |
cf3ca219c727
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
19 |
pow(B2, 3).size // -> 40 |
cf3ca219c727
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
20 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
val C = Set("a", "b", "") |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
22 |
pow(C, 2) |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
pow(C, 2).size // -> 7 |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
pow(C, 3) |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
26 |
pow(C, 3).size // -> 15 |
525 | 27 |
|
28 |
||
572 | 29 |
//val A = Set("a", "b", "c", "d") |
30 |
//pow(A, 4).size |
|
525 | 31 |
|
572 | 32 |
//val A = Set("a", "b", "c") |
33 |
//pow(A, 5).size |
|
525 | 34 |
|
572 | 35 |
//val A = Set("a", "b", "") |
36 |
//pow(A, 5).size |
|
564 | 37 |
|
38 |
||
572 | 39 |
for (n <- (0 to 6).toList) |
40 |
yield pow(B, n).size |
|
577 | 41 |
|
42 |
||
43 |
||
44 |
||
45 |
||
46 |
val A = Set("a", "b", "c") |
|
47 |
pow(A, 3) |
|
618 | 48 |
pow(A, 3).size |
577 | 49 |
|
50 |
val B = Set("a", "b", "") |
|
51 |
pow(B, 4) |
|
618 | 52 |
pow(B, 4).size |