diff -r 50ce3667c190 -r 9b71dead1219 progs/pow.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/progs/pow.scala Fri Nov 06 04:54:41 2015 +0000 @@ -0,0 +1,20 @@ +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 C = Set("a", "b", "") +pow(C, 2) +pow(C, 2).size // -> 7 + +pow(C, 3) +pow(C, 3).size // -> 15