--- a/progs/cube.sc Tue Dec 07 01:35:00 2021 +0000
+++ b/progs/cube.sc Tue Dec 07 23:17:51 2021 +0000
@@ -61,7 +61,7 @@
def pp_cube(c: Cube) : String =
s"${pp_face(c.f1)}\n${pp_face(c.f2)}\n${pp_face(c.f3)}\n${pp_face(c.f4)}\n${pp_face(c.f5)}\n${pp_face(c.f6)}"
-// specific cube
+
val init =
Cube(Face(White, Green, White, White),
Face(Blue, Yellow, Orange, Red),
@@ -137,7 +137,7 @@
def searchS(cs: Set[Cube], d: Int) : Boolean = {
println(s"Depth: $d Cands: ${cs.size}")
- //memory()
+ memory()
if (cs.exists(solved == _)) true
else searchS(cs.flatMap(actionsS), d + 1)
}
@@ -163,13 +163,13 @@
def search2(cs: List[(Cube, Actions)], d: Int) : (Cube, Actions) = {
println(s"Depth: $d Cands: ${cs.length}")
- val res = cs.find(solved == _._1)
+ val res = cs.find(init == _._1)
if (res.isDefined) res.get
else search2(cs.flatMap((actions2 _).tupled), d + 1)
}
//println("List Version with Actions")
-//println(search2(List((init, Nil)), 0)._2.mkString("\n"))
+//println(search2(List((solved, Nil)), 0)._2.mkString("\n"))
//println(s"${time_needed(1, search2(List((init, Nil)), 0))} secs")
// using Maps for recording the moves
@@ -181,13 +181,13 @@
def searchM(cs: Map[Cube, Actions], d: Int) : Actions = {
println(s"Depth: $d Cands: ${cs.keySet.size}")
- val res = cs.keySet.find(solved == _)
+ val res = cs.keySet.find(init == _)
if (res.isDefined) cs(res.get)
else searchM(cs.flatMap((actionsM _).tupled), d + 1)
}
println("Map Version with actions")
-println(searchM(Map(init -> Nil), 0).mkString("\n"))
+println(searchM(Map(solved -> Nil), 0).mkString("\n"))
println(s"${time_needed(1, searchM(Map(init -> Nil), 0))} secs")
@@ -205,3 +205,11 @@
println("Bidirectional Version with actions")
println(bsearch(Map(init -> Nil), Map(solved -> Nil), 0))
println(s"${time_needed(1, bsearch(Map(init -> Nil), Map(solved -> Nil), 0))}")
+
+
+
+
+
+
+// more memory
+// JAVA_OPTS="-Xmx2g"
\ No newline at end of file