scala/recs.scala
changeset 195 f06aa4e1c25b
parent 194 fc2a5e9fbb97
child 198 d93cc4295306
--- a/scala/recs.scala	Fri Feb 22 14:31:34 2013 +0000
+++ b/scala/recs.scala	Mon Feb 25 15:12:48 2013 +0000
@@ -34,19 +34,23 @@
 
 case class Pr(n: Int, f: Rec, g: Rec) extends Rec {
   override def eval(ns: List[Int]) = 
-    if (ns.length == n - 1) {
+    if (ns.length == n + 1) {
       if (ns.last == 0) f.eval(ns.init)
       else {
         val r = Pr(n, f, g).eval(ns.init ::: List(ns.last - 1))
         g.eval(ns.init ::: List(ns.last - 1, r))
       }
     }
-    else throw new IllegalArgumentException("Cn: args")
+    else throw new IllegalArgumentException("Pr: args")
 }
 
 case class Mn(n: Int, f: Rec) extends Rec {
-  override def eval(ns: List[Int]) = 0
-    
+  def evaln(ns: List[Int], n: Int) : Int = 
+    if (f.eval(ns ::: List(n)) == 0) n else evaln(ns, n + 1)
+
+  override def eval(ns: List[Int]) = 
+    if (ns.length == n) evaln(ns, 0) 
+    else throw new IllegalArgumentException("Mn: args")
 }
 
 }