progs/cube.scala
changeset 464 73ced118f73d
parent 463 0315d9983cd0
--- a/progs/cube.scala	Sat Mar 11 22:01:53 2023 +0000
+++ b/progs/cube.scala	Sat Mar 11 22:42:09 2023 +0000
@@ -1,6 +1,14 @@
 // 2 x 2 x 2 Rubik's Cube
 //========================
 
+// !! UPDATE for Scala 3
+// !! 
+// !! Scala 3 allocates much more memory to 
+// !! the JVM such that the memory issues from
+// !! Scala 2 and the video do not arise. 
+
+
+
 // for more memory for the JVM, call
 //
 // JAVA_OPTS="-Xmx2g" scala
@@ -142,7 +150,7 @@
   println(s"Depth: $d    Cands: ${cs.length}")  
   val res = cs.find(_._1 == solved)
   if (res.isDefined) res.get
-  else search_list(cs.flatMap{case (c, as) => actions_list(c, as) }, d + 1)
+  else search_list(cs.flatMap{ (c, as) => actions_list(c, as) }, d + 1)
 }  
 
 search_list(List((init, Nil)), 0)._2.reverse.mkString("\n") 
@@ -159,7 +167,7 @@
   println(s"Depth: $d    Cands: ${cs.keySet.size}")  
   val res = cs.keySet.find(_ == solved)
   if (res.isDefined) cs(res.get)
-  else search_map(cs.flatMap{case (c, as) => actions_list(c, as) }, d + 1)
+  else search_map(cs.flatMap{ (c, as) => actions_list(c, as) }, d + 1)
 }  
 
 
@@ -173,20 +181,6 @@
   println(s"Depth: $d    Cands: ${cs.keySet.size}/${bs.keySet.size}") 
   val res = cs.keySet intersect bs.keySet 
   if (!res.isEmpty) (cs(res.head).reverse ::: bs(res.head))
-  else bsearch(cs.flatMap{case (c, as) => actions_map(c, as) }, 
-               bs.flatMap{case (c, as) => actions_map(c, as) }, d + 1)
-}  
-
-bsearch(Map(init ->  Nil), Map(solved -> Nil), 0).mkString("\n")
-
-
-
-// bidirectional breadth-first search
-def bsearch(cs: Map[Cube, Actions], 
-            bs: Map[Cube, Actions], d: Int) : Actions = { 
-  println(s"Depth: $d    Cands: ${cs.keySet.size}/${bs.keySet.size}") 
-  val res = cs.keySet intersect bs.keySet 
-  if (!res.isEmpty) (cs(res.head).reverse ::: bs(res.head))
   else bsearch(cs.flatMap{ (c, as) => actions_map(c, as) }, 
                bs.flatMap{ (c, as) => actions_map(c, as) }, d + 1)
 }