--- a/solutions5/bfc.scala Sun Aug 23 14:39:58 2020 +0100
+++ b/solutions5/bfc.scala Tue Aug 25 01:18:17 2020 +0100
@@ -170,14 +170,16 @@
// that is write(mem, mp, 0).
//
// The easiest way to modify a string in this way is to use the regular
-// expression """[^<>+-.\[\]]""", which recognises everything that is
+// expression """[^<>+-.\[\]@*#]""", which recognises everything that is
// not a bf-command and replace it by the empty string. Similarly the
// regular expression """\[-\]""" finds all occurences of [-] and
// by using the Scala method .replaceAll you can repplace it with the
// string "0" standing for the new bf-command.
-def optimise(s: String) : String =
- s.replaceAll("""[^<>+-.\[\]]""","").replaceAll("""\[-\]""", "0")
+def optimise(s: String) : String = {
+ s.replaceAll("""[^<>+-.\[\]@*#]""","")
+ .replaceAll("""\[-\]""", "0")
+}
def compute3(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
@@ -208,6 +210,7 @@
// testcases
+//println(optimise(load_bff("collatz.bf")))
//optimise(load_bff("benchmark.bf")) // should have inserted 0's
//optimise(load_bff("mandelbrot.bf")).length // => 11203
@@ -291,6 +294,8 @@
}
// testcases
+//println(combine(optimise(load_bff("collatz.bf"))))
+
//combine(optimise(load_bff("benchmark.bf"))) // => """>A+B[<A+M>A-A]<A[[....."""
//time_needed(1, run4(load_bff("benchmark.bf")))