equal
deleted
inserted
replaced
29 println(s"In the range of 1 - ${bnd} the number ${max} needs the maximum steps of ${steps}") |
29 println(s"In the range of 1 - ${bnd} the number ${max} needs the maximum steps of ${steps}") |
30 } |
30 } |
31 |
31 |
32 */ |
32 */ |
33 |
33 |
|
34 def is_pow(n: Long) : Boolean = (n & (n - 1)) == 0 |
|
35 |
|
36 def is_hard(n: Long) : Boolean = is_pow(3 * n + 1) |
|
37 |
|
38 def last_odd(n: Long) : Long = |
|
39 if (is_hard(n)) n else |
|
40 if (n % 2 == 0) last_odd(n / 2) else |
|
41 last_odd(3 * n + 1) |
|
42 |
|
43 |
|
44 //for (i <- 1 to 130) println(s"$i: ${last_odd(i)}") |
|
45 |
34 } |
46 } |
|
47 |
|
48 |
|
49 |