--- a/progs/pow.scala Sun Oct 02 08:42:01 2022 +0100
+++ b/progs/pow.scala Sun Oct 09 13:39:34 2022 +0100
@@ -3,16 +3,29 @@
def pow(A: Set[String], n: Int) : Set[String] = n match {
case 0 => Set("")
- case n => concat(A, pow(A, n- 1))
+ case n => concat(A, pow(A, n - 1))
}
+def powT(A: Set[String], n: Int, acc: Set[String] = Set("")) : Set[String] =
+ n match {
+ case 0 => acc
+ case n => powT(A, n - 1, concat(acc, A))
+ }
+
+
val A = Set("a", "b", "c", "d", "e")
val B = Set("a", "b", "c", "d", "")
pow(A, 4).size
pow(B, 4).size
+powT(A, 4).size
+powT(B, 4).size
-val A = Set("aa", "a")
+val C = Set("a", "b")
+
+pow(C, 100).size
+powT(C, 100000)
+
val B = Set("aaa", "aaaa")
concat(A, B).size // -> 3