--- a/progs/re2_sol.scala Wed Jan 25 14:51:09 2017 +0000
+++ b/progs/re2_sol.scala Wed Jan 25 17:23:00 2017 +0000
@@ -157,15 +157,10 @@
//non-tail recursive iter
-def iter[A](n: Int, f: A => A, x: A): A =
- if (n == 0) x else f(iter(n - 1,f, x))
+//def iter[A](n: Int, f: A => A)(x: A): A =
+// if (n == 0) x else f(iter(n - 1,f, x))
-iter(200000, (x: Int) => x + 1, 0)
-iterT(200000, (x: Int) => x + 1, 0)
-iterT(100, (x: Int) => x * 2, 2)
-iterT(100, (x: BigInt) => x * 2, BigInt(2))
-iterT(10, (x: String) => x ++ "a", "a")
// (2b)
@@ -192,8 +187,6 @@
if (fx == x) x else fixpT(f, fx)
}
-fixpT((x:Int) => if (200000 < x) x else x + 1, 0)
-
def ctest(n: Long): Long =
if (n == 1) 1 else
if (n % 2 == 0) n / 2 else 3 * n + 1