progs/pow.scala
changeset 564 b5d57d7064bb
parent 525 a2ee4b11c976
child 572 4a1739f256fd
equal deleted inserted replaced
563:bddf14e026b3 564:b5d57d7064bb
     1 def concat(A: Set[String], B: Set[String]) : Set[String] =
     1 def concat(A: Set[String], B: Set[String]) : Set[String] =
     2   for (x <-A ; y <- B) yield x ++ y
     2   for (x <- A ; y <- B) yield x ++ y
     3 
     3 
     4 def pow(A: Set[String], n: Int) : Set[String] = n match {
     4 def pow(A: Set[String], n: Int) : Set[String] = n match {
     5   case 0 => Set("")
     5   case 0 => Set("")
     6   case n => concat(A, pow(A, n- 1))
     6   case n => concat(A, pow(A, n- 1))
     7 }
     7 }
    31 val A = Set("a", "b", "c")
    31 val A = Set("a", "b", "c")
    32 pow(A, 5).size   
    32 pow(A, 5).size   
    33 
    33 
    34 val A = Set("a", "b", "")
    34 val A = Set("a", "b", "")
    35 pow(A, 5).size   
    35 pow(A, 5).size   
       
    36 
       
    37 
       
    38 for (n <- (0 to 12).toList) 
       
    39   yield pow(A, n).size