--- a/progs/collatz_sol2.scala Tue Nov 15 23:08:09 2016 +0000
+++ b/progs/collatz_sol2.scala Wed Nov 16 14:37:18 2016 +0000
@@ -15,7 +15,7 @@
// an alternative that calculates the steps directly
-def collatz1(n: Long): Int =
+def collatz1(n: Long): Long =
if (n == 1) 1 else
if (n % 2 == 0) (1 + collatz1(n / 2)) else
(1 + collatz1(3 * n + 1))
@@ -37,13 +37,15 @@
// upto 1 million.
def collatz_max(bnd: Long): (Long, Long) = {
- (1L to bnd).view.map((i) => (collatz2(i, 1), i)).maxBy(_._1)
+ (1L to bnd).view.map((i) => (collatz1(i), i)).maxBy(_._1)
}
// some testing harness
//val bnds = List(10, 100, 1000, 10000, 100000, 1000000)
-val bnds = List(10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000)
+val bnds = List(10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 2000000000)
+
+
for (bnd <- bnds) {
val (steps, max) = collatz_max(bnd)