| changeset 123 | 006f71e905a1 |
| parent 64 | d6f97b562424 |
| child 127 | 01d522ba48d4 |
| 122:40147ad17bdf | 123:006f71e905a1 |
|---|---|
1 // Part 1 about the 3n+1 conceture |
1 // Part 1 about the 3n+1 conceture |
2 //================================= |
2 //================================= |
3 |
|
4 |
|
3 |
5 |
4 //(1) Complete the collatz function below. It should |
6 //(1) Complete the collatz function below. It should |
5 // recursively calculate the number of steps needed |
7 // recursively calculate the number of steps needed |
6 // until the collatz series reaches the number 1. |
8 // until the collatz series reaches the number 1. |
7 // If needed you can use an auxilary function that |
9 // If needed you can use an auxilary function that |
34 (all.indexOf(max) + 1, max) |
36 (all.indexOf(max) + 1, max) |
35 } |
37 } |
36 |
38 |
37 |
39 |
38 // some testing harness |
40 // some testing harness |
39 val bnds = List(2, 10, 100, 1000, 10000, 100000, 77000, 90000, 1000000) |
41 val bnds = List(2, 10, 100, 1000, 10000, 100000, 77000, 90000, 1000000, 5000000) |
40 |
42 |
41 for (bnd <- bnds) { |
43 for (bnd <- bnds) { |
42 val (max, steps) = collatz_max(bnd) |
44 val (max, steps) = collatz_max(bnd) |
43 println(s"In the range of 1 - ${bnd} the number ${max} needs the maximum steps of ${steps}") |
45 println(s"In the range of 1 - ${bnd} the number ${max} needs the maximum steps of ${steps}") |
44 } |
46 } |
45 |
47 |
46 |
48 |
47 //val all = for (i <- (1 to 100000).toList) yield collatz1(i) |
49 //val all = for (i <- (1 to 100000).toList) yield collatz1(i) |
48 //println(all.sorted.reverse.take(10)) |
50 //println(all.sorted.reverse.take(10)) |
51 |
|
52 |
|
53 |