pre_testing1/collatz.scala
changeset 360 1bd1e9cd8c72
parent 346 ed1b6b8c36e5
child 362 fc9394f4f0ea
equal deleted inserted replaced
359:c58105a9a329 360:1bd1e9cd8c72
    19 
    19 
    20 //collatz_max(1000000)
    20 //collatz_max(1000000)
    21 //collatz_max(10000000)
    21 //collatz_max(10000000)
    22 //collatz_max(100000000)
    22 //collatz_max(100000000)
    23 
    23 
    24 
       
    25 /* some test cases
    24 /* some test cases
    26 val bnds = List(10, 100, 1000, 10000, 100000, 1000000)
    25 val bnds = List(10, 100, 1000, 10000, 100000, 1000000)
    27 
    26 
    28 for (bnd <- bnds) {
    27 for (bnd <- bnds) {
    29   val (steps, max) = collatz_max(bnd)
    28   val (steps, max) = collatz_max(bnd)
    41     if (n % 2 == 0) last_odd(n / 2) else 
    40     if (n % 2 == 0) last_odd(n / 2) else 
    42       last_odd(3 * n + 1)
    41       last_odd(3 * n + 1)
    43 
    42 
    44 
    43 
    45 //for (i <- 130 to 10000) println(s"$i: ${last_odd(i)}")
    44 //for (i <- 130 to 10000) println(s"$i: ${last_odd(i)}")
    46 for (i <- 1 to 100) println(s"$i: ${collatz(i)}")
    45 //for (i <- 1 to 100) println(s"$i: ${collatz(i)}")
    47 
    46 
    48 }
    47 }
    49 
    48 
    50 
    49 
    51 
    50