testing1/collatz.scala
changeset 197 c3e39fdeea3b
parent 171 4c9497ab5caa
child 199 54befaf23648
equal deleted inserted replaced
196:c50b074b3047 197:c3e39fdeea3b
    19 
    19 
    20 
    20 
    21 }
    21 }
    22 
    22 
    23 
    23 
    24 def Collat(n: Long, r: Int = 1) : Int = 
       
    25   if (n == 1) r else
       
    26    if (n % 2 == 0) Collat(n / 2 , r + 1) else
       
    27      Collat (3 * n + 1 , r + 1)
       
    28 
    24 
    29 (1 to 10).map(collatz(_))
    25 (1 to 10).map(collatz(_))