progs/pow.scala
changeset 650 b34efa58f7d5
parent 638 e951b9688bb2
child 669 e22b5faa7e66
equal deleted inserted replaced
649:12c4957c15a9 650:b34efa58f7d5
     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 }
       
     8 
       
     9 val A = Set("1", "2", "3", "")
       
    10 val B = Set("1", "2", "3", "4", "5", "6", "")
       
    11 concat(A, B).size                     // -> 28 
       
    12 pow(B, 3).size 
       
    13 
     8 
    14 
     9 val A = Set("a", "b", "c", "d")
    15 val A = Set("a", "b", "c", "d")
    10 pow(A, 4).size                            // -> 256
    16 pow(A, 4).size                            // -> 256
    11 
    17 
    12 val B = Set("a", "b", "c", "")
    18 val B = Set("a", "b", "c", "")