changeset 365 | 9b71dead1219 |
child 397 | cf3ca219c727 |
364:50ce3667c190 | 365:9b71dead1219 |
---|---|
1 def concat(A: Set[String], B: Set[String]) : Set[String] = |
|
2 for (x <-A ; y <- B) yield x ++ y |
|
3 |
|
4 def pow(A: Set[String], n: Int) : Set[String] = n match { |
|
5 case 0 => Set("") |
|
6 case n => concat(A, pow(A, n- 1)) |
|
7 } |
|
8 |
|
9 val A = Set("a", "b", "c", "d") |
|
10 pow(A, 4).size // -> 256 |
|
11 |
|
12 val B = Set("a", "b", "c", "") |
|
13 pow(B, 4).size // -> 121 |
|
14 |
|
15 val C = Set("a", "b", "") |
|
16 pow(C, 2) |
|
17 pow(C, 2).size // -> 7 |
|
18 |
|
19 pow(C, 3) |
|
20 pow(C, 3).size // -> 15 |