progs/lecture3.scala
changeset 449 d67c5f7177a6
parent 448 db2a3e3287a9
child 481 e03a0100ec46
--- a/progs/lecture3.scala	Fri Nov 25 00:03:15 2022 +0000
+++ b/progs/lecture3.scala	Fri Dec 02 07:48:03 2022 +0000
@@ -1,9 +1,18 @@
 // Scala Lecture 3
 //=================
 
+// - Higher-Order functions
 // - maps (behind for-comprehensions)
+
 // - Pattern-Matching
 
+def fib(n: Int) : Int = n match {
+  case 0 => 1
+  case 1 =>  1
+  case n => fib(n - 1) + fib(n - 2)
+}
+
+
 abstract class Rexp
 case object ZERO extends Rexp                      // matches nothing
 case object ONE extends Rexp                       // matches the empty string
@@ -310,6 +319,7 @@
 // Sudoku
 //========
 
+// uses Strings for games
 
 type Pos = (Int, Int)
 val emptyValue = '.'
@@ -349,8 +359,8 @@
 def search(game: String): List[String] = {
   if (isDone(game)) List(game)
   else 
-    candidates(game, emptyPosition(game)).par.
-      map(c => search(update(game, empty(game), c))).toList.flatten
+    candidates(game, emptyPosition(game)).
+      map(c => search(update(game, empty(game), c))).flatten
 }