--- a/cws/main_cw05.tex Mon Nov 02 02:31:44 2020 +0000
+++ b/cws/main_cw05.tex Mon Nov 02 13:10:02 2020 +0000
@@ -27,7 +27,7 @@
brainf***. Actually, we will implement an interpreter for our own version
of this language called brainf*ck++.\bigskip
-\IMPORTANT{This part is worth 10\% and you need to submit it on \cwTEN{} at 4pm.}
+\IMPORTANT{This part is worth 10\% and you need to submit it on \cwTEN{} at 5pm.}
\noindent
Also note that the running time of each part will be restricted to a
Binary file main_solution1/drumb.jar has changed
--- a/main_solution1/drumb.scala Mon Nov 02 02:31:44 2020 +0000
+++ b/main_solution1/drumb.scala Mon Nov 02 13:10:02 2020 +0000
@@ -24,7 +24,7 @@
// strings for each line in the CSV-file.
def get_january_data(symbol: String, year: Int) : List[String] =
- Source.fromFile(symbol ++ ".csv")("ISO-8859-1").getLines.toList.filter(_.startsWith(year.toString))
+ Source.fromFile(symbol ++ ".csv")("ISO-8859-1").getLines().toList.filter(_.startsWith(year.toString))
//test cases
Binary file main_solution2/danube.jar has changed
Binary file main_solution3/re.jar has changed
Binary file main_solution4/knight2.jar has changed
Binary file main_solution4/knight3.jar has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_solution5/benchmark.bf Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,4 @@
+>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
+[>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
+++++++++[>++++++++++[>++++++++++[>++++++++++[>+
++++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++.
\ No newline at end of file
Binary file main_solution5/bf.jar has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_solution5/bf.scala Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,227 @@
+// Core Part about an Interpreter for
+// the Brainf***++ language
+//==============================================
+
+object CW10a {
+
+
+// representation of Bf memory
+
+type Mem = Map[Int, Int]
+
+
+// (1) Write a function that takes a file name as argument and
+// and requests the corresponding file from disk. It Returns the
+// content of the file as a String. If the file does not exists,
+// the function should Return the empty string.
+
+import io.Source
+import scala.util._
+
+def load_bff(name: String) : String =
+ Try(Source.fromFile(name)("ISO-8859-1").mkString).getOrElse("")
+
+
+// (2) Complete the functions for safely reading
+// and writing brainf***++ memory. Safely read should
+// Return the value stored in the Map for a given memory
+// pointer, provided it exists; otherwise it Returns 0. The
+// writing function generates a new Map with the
+// same data, except at the given memory pointer the
+// value v is stored.
+
+
+def sread(mem: Mem, mp: Int) : Int =
+ mem.getOrElse(mp, 0)
+
+def write(mem: Mem, mp: Int, v: Int) : Mem =
+ mem.updated(mp, v)
+
+
+// (3) Implement the two jumping instructions in the
+// brainf***++ language. In jumpRight, given a program and
+// a program counter move the program counter to the right
+// until after the *matching* ]-command. Similarly,
+// jumpLeft implements the move to the left to just after
+// the *matching* [-command.
+
+def jumpRight(prog: String, pc: Int, level: Int) : Int = {
+ if (prog.length <= pc) pc
+ else (prog(pc), level) match {
+ case (']', 0) => pc + 1
+ case (']', l) => jumpRight(prog, pc + 1, l - 1)
+ case ('[', l) => jumpRight(prog, pc + 1, l + 1)
+ case (_, l) => jumpRight(prog, pc + 1, l)
+ }
+}
+
+def jumpLeft(prog: String, pc: Int, level: Int) : Int = {
+ if (pc < 0) pc
+ else (prog(pc), level) match {
+ case ('[', 0) => pc + 1
+ case ('[', l) => jumpLeft(prog, pc - 1, l - 1)
+ case (']', l) => jumpLeft(prog, pc - 1, l + 1)
+ case (_, l) => jumpLeft(prog, pc - 1, l)
+ }
+}
+
+// test cases
+//jumpRight("""--[..+>--].>.++""", 3, 0) // => 10
+//jumpLeft("""--[..+>--].>.++""", 8, 0) // => 3
+//jumpRight("""--[..[+>]--].>.++""", 3, 0) // => 12
+//jumpRight("""--[..[[-]+>[.]]--].>.++""", 3, 0) // => 18
+//jumpRight("""--[..[[-]+>[.]]--.>.++""", 3, 0) // => 22 (outside)
+//jumpLeft("""[******]***""", 7, 0) // => -1 (outside)
+
+// (4) Complete the compute function that interprets (runs) a brainf***++
+// program: the arguments are a program (represented as a string), a program
+// counter, a memory counter and a brainf***++ memory. It Returns the
+// memory at the stage when the execution of the brainf***++ program
+// finishes. The interpretation finishes once the program counter
+// pc is pointing to something outside the program string.
+// If the pc points to a character inside the program, the pc,
+// memory pointer and memory need to be updated according to
+// rules of the brainf***++ language. Then, recursively, the compute
+// function continues with the command at the new program
+// counter.
+//
+// Implement the run function that calls compute with the program
+// counter and memory counter set to 0.
+
+def compute(prog: String, pc: Int, mp: Int, mem: Mem) : Mem = {
+ if (0 <= pc && pc < prog.length) {
+ val (new_pc, new_mp, new_mem) = prog(pc) match {
+ case '>' => (pc + 1, mp + 1, mem)
+ case '<' => (pc + 1, mp - 1, mem)
+ case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
+ case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
+ case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
+ //case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
+ //case ',' => (pc + 1, mp, write(mem, mp, scala.io.StdIn.readByte()))
+ case '[' =>
+ if (sread(mem, mp) == 0) (jumpRight(prog, pc + 1, 0), mp, mem) else (pc + 1, mp, mem)
+ case ']' =>
+ if (sread(mem, mp) != 0) (jumpLeft(prog, pc - 1, 0), mp, mem) else (pc + 1, mp, mem)
+
+ // new commands
+ case '@' => (pc + 1, mp, write(mem, sread(mem, mp), sread(mem, mp - 1)))
+ case '*' => (pc + 1, mp, write(mem, mp, sread(mem, mp) * sread(mem, mp -1)))
+ case '#' => { println(s"${sread(mem, mp)}"); (pc + 1, mp, mem) }
+
+ case _ => (pc + 1, mp, mem)
+ }
+ compute(prog, new_pc, new_mp, new_mem)
+ }
+ else mem
+}
+
+def run(prog: String, m: Mem = Map()) = compute(prog, 0, 0, m)
+
+
+
+
+
+// some sample bf/bf++-programs collected from the Internet
+//==========================================================
+
+
+// some contrived (small) programs
+//---------------------------------
+
+// clears the 0-cell
+//run("[-]", Map(0 -> 100)) // Map will be 0 -> 0
+
+// moves content of the 0-cell to 1-cell
+//run("[->+<]", Map(0 -> 10)) // Map will be 0 -> 0, 1 -> 10
+
+
+// copies content of the 0-cell to 2-cell and 4-cell
+//run("[>>+>>+<<<<-]", Map(0 -> 42)) // Map(0 -> 0, 2 -> 42, 4 -> 42)
+
+
+// prints out numbers 0 to 9
+//run("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""")
+
+// bf++ program calculating the cube-function, 10 * 10 * 10 = 1000
+//run("""++++++++++#>+***#""") // Map(0 -> 10, 1 -> 1000)
+
+
+// bf++ program copies 3 from 0-cell to to cells 1, 4, 5, 6 and 7
+// (note that because of how the program wprks cell 1 will contain 7)
+//run("""+++>+@+@+@+@+@""") // Map(0 -> 3, 1 -> 7, 4 -> 3, 5 -> 3, 6 -> 3, 7 -> 3)
+
+
+
+// some more "useful" programs
+//-----------------------------
+
+// hello world program 1
+//run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
+// ..+++.>>.<-.<.+++.------.--------.>>+.>++.""")
+
+// hello world program 2
+//run("""++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>+
+// +.<<+++++++++++++++.>.+++.------.--------.>+.>.""")
+
+// hello world program 3
+//run("""+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..
+// +++.>-.------------.<++++++++.--------.+++.------.--------.>+.""")
+
+
+// draws the Sierpinski triangle
+//run(load_bff("sierpinski.bf"))
+
+
+//fibonacci numbers below 100
+//run("""+++++++++++
+// >+>>>>++++++++++++++++++++++++++++++++++++++++++++
+// >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
+// +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
+// <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
+// -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
+// >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
+// +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
+// ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
+// <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
+// [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]""")
+
+//outputs the square numbers up to 10000
+//run("""++++[>+++++<-]>[<+++++>-]+<+[>[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+
+// >>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]
+// <<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]""")
+
+
+// calculates 2 to the power of 6
+//(example from a C-to-BF compiler at https://github.com/elikaski/BF-it)
+//run(""">>[-]>[-]++>[-]++++++><<<>>>>[-]+><>[-]<<[-]>[>+<<+>-]>[<+>-]
+// <><[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-]
+// <[>+>+<<-]>[<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<[[-]>[-]<<[>+>
+// +<<-]>>[<<+>>-][-]>[-]<<<<<[>>>>+>+<<<<<-]>>>>>[<<<<<+>>>>>-]
+// <<>>[-]>[-]<<<[>>>+<<<-]>>>[<<[<+>>+<-]>[<+>-]>-]<<<>[-]<<[-]
+// >[>+<<+>-]>[<+>-]<><[-]>[-]<<<[>>+>+<<<-]>>>-[<<<+>>>-]<[-]>[-]
+// <<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-]<[>+>+<<-]>
+// [<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<][-]>[-]<<[>+>+<<-]>>[<<+>
+// >-]<<<<<[-]>>>>[<<<<+>>>>-]<<<<><>[-]<<[-]>[>+<<+>-]>[<+>-]<>
+// <[-]>[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-]<<>>[-]>[-]>[-]>[-]>[-]>
+// [-]>[-]>[-]>[-]>[-]<<<<<<<<<<>>++++++++++<<[->+>-[>+>>]>[+[-<+
+// >]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<
+// ]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++
+// ++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<<><<<""")
+
+
+
+// a Mandelbrot set generator in brainf*** written by Erik Bosman
+// (http://esoteric.sange.fi/brainfuck/utils/mandelbrot/)
+//
+//run(load_bff("mandelbrot.bf"))
+
+
+// a benchmark program (counts down from 'Z' to 'A')
+//
+//run(load_bff("benchmark.bf"))
+
+// calculates the Collatz series for numbers from 1 to 30
+//
+//run(load_bff("collatz.bf"))
+
+}
Binary file main_solution5/bfc.jar has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_solution5/bfc.scala Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,317 @@
+// Part 2 about a "Compiler" for the Brainf*** language
+//======================================================
+
+object CW10b {
+
+// !!! Copy any function you need from file bf.scala !!!
+//
+// If you need any auxiliary function, feel free to
+// implement it, but do not make any changes to the
+// templates below.
+
+
+def time_needed[T](n: Int, code: => T) = {
+ val start = System.nanoTime()
+ for (i <- 0 until n) code
+ val end = System.nanoTime()
+ (end - start)/(n * 1.0e9)
+}
+
+type Mem = Map[Int, Int]
+
+
+import io.Source
+import scala.util._
+
+def load_bff(name: String) : String =
+ Try(Source.fromFile(name)("ISO-8859-1").mkString).getOrElse("")
+
+def sread(mem: Mem, mp: Int) : Int =
+ mem.getOrElse(mp, 0)
+
+def write(mem: Mem, mp: Int, v: Int) : Mem =
+ mem.updated(mp, v)
+
+def jumpRight(prog: String, pc: Int, level: Int) : Int = {
+ if (prog.length <= pc) pc
+ else (prog(pc), level) match {
+ case (']', 0) => pc + 1
+ case (']', l) => jumpRight(prog, pc + 1, l - 1)
+ case ('[', l) => jumpRight(prog, pc + 1, l + 1)
+ case (_, l) => jumpRight(prog, pc + 1, l)
+ }
+}
+
+def jumpLeft(prog: String, pc: Int, level: Int) : Int = {
+ if (pc < 0) pc
+ else (prog(pc), level) match {
+ case ('[', 0) => pc + 1
+ case ('[', l) => jumpLeft(prog, pc - 1, l - 1)
+ case (']', l) => jumpLeft(prog, pc - 1, l + 1)
+ case (_, l) => jumpLeft(prog, pc - 1, l)
+ }
+}
+
+def compute(prog: String, pc: Int, mp: Int, mem: Mem) : Mem = {
+ if (0 <= pc && pc < prog.length) {
+ val (new_pc, new_mp, new_mem) = prog(pc) match {
+ case '>' => (pc + 1, mp + 1, mem)
+ case '<' => (pc + 1, mp - 1, mem)
+ case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
+ case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
+ case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
+ case '[' =>
+ if (sread(mem, mp) == 0) (jumpRight(prog, pc + 1, 0), mp, mem) else (pc + 1, mp, mem)
+ case ']' =>
+ if (sread(mem, mp) != 0) (jumpLeft(prog, pc - 1, 0), mp, mem) else (pc + 1, mp, mem)
+ case _ => (pc + 1, mp, mem)
+ }
+ compute(prog, new_pc, new_mp, new_mem)
+ }
+ else mem
+}
+
+def run(prog: String, m: Mem = Map()) = compute(prog, 0, 0, m)
+
+
+// The baseline to what we can compare our "compiler"
+// implemented below. It should require something like
+// 60 seconds for the calculation on my laptop
+//
+//time_needed(1, run(load_bff("benchmark.bf")))
+
+
+
+// DEBUGGING INFORMATION!!!
+//
+// Compiler, even real ones, are fiedishly difficult to get
+// to prduce correct code. The point is that for example for
+// the sierpinski program, they need to still generate code
+// that displays such a triangle. If yes, then one usually
+// can take comfort that all is well. If not, then something
+// went wrong during the optimisations.
+
+
+
+// (5) Write a function jtable that precomputes the "jump
+// table" for a bf-program. This function takes a bf-program
+// as an argument and Returns a Map[Int, Int]. The
+// purpose of this map is to record the information
+// that given on the position pc is a '[' or a ']',
+// then to which pc-position do we need to jump next?
+//
+// For example for the program
+//
+// "+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]"
+//
+// we obtain the map
+//
+// Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)
+//
+// This states that for the '[' on position 5, we need to
+// jump to position 20, which is just after the corresponding ']'.
+// Similarly, for the ']' on position 19, we need to jump to
+// position 6, which is just after the '[' on position 5, and so
+// on. The idea is to not calculate this information each time
+// we hit a bracket, but just look up this information in the
+// jtable. You can use the jumpLeft and jumpRight functions
+// from Part 1 for calculating the jtable.
+//
+// Then adapt the compute and run functions from Part 1 in order
+// to take advantage of the information stored in the jtable.
+// This means whenever jumpLeft and jumpRight was called previously,
+// you should look up the jump address in the jtable.
+
+
+def jtable(pg: String) : Map[Int, Int] =
+ (0 until pg.length).collect { pc => pg(pc) match {
+ case '[' => (pc -> jumpRight(pg, pc + 1, 0))
+ case ']' => (pc -> jumpLeft(pg, pc - 1, 0))
+ }}.toMap
+
+
+// testcase
+// jtable("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""")
+// => Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)
+
+
+def compute2(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
+ if (0 <= pc && pc < pg.length) {
+ val (new_pc, new_mp, new_mem) = pg(pc) match {
+ case '>' => (pc + 1, mp + 1, mem)
+ case '<' => (pc + 1, mp - 1, mem)
+ case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
+ case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
+ case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
+ case '[' =>
+ if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
+ case ']' =>
+ if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
+ case _ => (pc + 1, mp, mem)
+ }
+ compute2(pg, tb, new_pc, new_mp, new_mem)
+ }
+ else mem
+}
+
+
+def run2(pg: String, m: Mem = Map()) =
+ compute2(pg, jtable(pg), 0, 0, m)
+
+//time_needed(1, run2(load_bff("benchmark.bf")))
+
+
+
+// (6) Write a function optimise which deletes "dead code" (everything
+// that is not a bf-command) and also replaces substrings of the form
+// [-] by a new command 0. The idea is that the loop [-] just resets the
+// memory at the current location to 0. In the compute3 and run3 functions
+// below you implement this command by writing the number 0 to mem(mp),
+// 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
+// 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 compute3(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
+ if (0 <= pc && pc < pg.length) {
+ val (new_pc, new_mp, new_mem) = pg(pc) match {
+ case '0' => (pc + 1, mp, write(mem, mp, 0))
+ case '>' => (pc + 1, mp + 1, mem)
+ case '<' => (pc + 1, mp - 1, mem)
+ case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
+ case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
+ case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
+ case '[' =>
+ if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
+ case ']' =>
+ if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
+ case _ => (pc + 1, mp, mem)
+ }
+ compute3(pg, tb, new_pc, new_mp, new_mem)
+ }
+ else mem
+}
+
+def run3(pg: String, m: Mem = Map()) = {
+ val pg_opt = optimise(pg)
+ compute3(pg_opt, jtable(pg_opt), 0, 0, m)
+}
+
+
+// testcases
+
+//println(optimise(load_bff("collatz.bf")))
+//optimise(load_bff("benchmark.bf")) // should have inserted 0's
+//optimise(load_bff("mandelbrot.bf")).length // => 11203
+
+//time_needed(1, run3(load_bff("benchmark.bf")))
+
+
+
+// (7) Write a function combine which replaces sequences
+// of repated increment and decrement commands by appropriate
+// two-character commands. For example for sequences of +
+//
+// orig bf-cmds | replacement
+// ------------------------------
+// + | +A
+// ++ | +B
+// +++ | +C
+// |
+// ... |
+// |
+// +++....+++ | +Z
+// (where length = 26)
+//
+// Similar for the bf-command -, > and <. All other commands should
+// be unaffected by this change.
+//
+// Adapt the compute4 and run4 functions such that they can deal
+// appropriately with such two-character commands.
+
+def splice(cs: List[Char], acc: List[(Char, Int)]) : List[(Char, Int)] = (cs, acc) match {
+ case (Nil, acc) => acc
+ case ('[' :: cs, acc) => splice(cs, ('[', 1) :: acc)
+ case (']' :: cs, acc) => splice(cs, (']', 1) :: acc)
+ case ('.' :: cs, acc) => splice(cs, ('.', 1) :: acc)
+ case ('0' :: cs, acc) => splice(cs, ('0', 1) :: acc)
+ case (c :: cs, Nil) => splice(cs, List((c, 1)))
+ case (c :: cs, (d, n) :: acc) =>
+ if (c == d && n < 26) splice(cs, (c, n + 1) :: acc)
+ else splice(cs, (c, 1) :: (d, n) :: acc)
+}
+
+def spl(s: String) = splice(s.toList, Nil).reverse
+
+//spl(load_bff("benchmark.bf"))
+
+def combine(s: String) : String = {
+ (for ((c, n) <- spl(s)) yield c match {
+ case '>' => List('>', (n + '@').toChar)
+ case '<' => List('<', (n + '@').toChar)
+ case '+' => List('+', (n + '@').toChar)
+ case '-' => List('-', (n + '@').toChar)
+ case _ => List(c)
+ }).flatten.mkString
+}
+
+
+//combine(load_bff("benchmark.bf"))
+
+def compute4(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
+ if (0 <= pc && pc < pg.length) {
+ val (new_pc, new_mp, new_mem) = pg(pc) match {
+ case '0' => (pc + 1, mp, write(mem, mp, 0))
+ case '>' => (pc + 2, mp + (pg(pc + 1) - '@'), mem)
+ case '<' => (pc + 2, mp - (pg(pc + 1) - '@'), mem)
+ case '+' => (pc + 2, mp, write(mem, mp, sread(mem, mp) + (pg(pc + 1) - '@')))
+ case '-' => (pc + 2, mp, write(mem, mp, sread(mem, mp) - (pg(pc + 1) - '@')))
+ case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
+ case '[' =>
+ if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
+ case ']' =>
+ if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
+ case _ => (pc + 1, mp, mem)
+ }
+ compute4(pg, tb, new_pc, new_mp, new_mem)
+ }
+ else mem
+}
+
+def run4(pg: String, m: Mem = Map()) = {
+ val pg_opt = combine(optimise(pg))
+ compute4(pg_opt, jtable(pg_opt), 0, 0, m)
+}
+
+// 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")))
+
+//time_needed(1, run(load_bff("sierpinski.bf")))
+//time_needed(1, run4(load_bff("sierpinski.bf")))
+
+//println(time_needed(1, run4(load_bff("mandelbrot.bf"))))
+
+
+}
+
+/*
+import CW10b._
+println(time_needed(1, run(load_bff("collatz.bf"))))
+println(time_needed(1, run2(load_bff("collatz.bf"))))
+println(time_needed(1, run3(load_bff("collatz.bf"))))
+println(time_needed(1, run4(load_bff("collatz.bf"))))
+*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_solution5/collatz.bf Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,2 @@
+
+>++++[<++++++++++>-]<+++++++++.[-]>+++++[<++++++++++>-]<++++++++.[-]>+++[<++++++++++>-]<++.[-]>++++[<++++++++++>-]<+++++++++.[-]>+++[<++++++++++>-]<++.[-]>++++++[<++++++++++>-]<+.[-]>++++++[<++++++++++>-]<++.[-]>+++[<++++++++++>-]<++.[-]>++++[<++++++++++>-]<++++++++.[-]++++++++++.[-]++>+[<[>>+>+<<<-]>>>[<<<+>>>-]<+>>+++[<++++++++++>-]<+>>+<<<[>>+<<-]>>[>-]>[<<<+>[-]>>->]<+<<[>-[>-]>[<<<+>[-]+>>->]<+<<-]>[-]>-<<<[<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]>>>>>>>>>>>>>>>>>>>+>+[<<<<<<<<<<<<<<<<<<<<<[>>>>>>>>>>>>>>>>>>>>>>+>+<<<<<<<<<<<<<<<<<<<<<<<-]>>>>>>>>>>>>>>>>>>>>>>>[<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>>-]>>+<<<[>>+<<-]>>[>-]>[<<<+>[-]>>->]<+<<[>-[>-]>[<<<+>[-]+>>->]<+<<-]>[-]>-<<<[>+<[-]]+>[<->-]<[<<<<<<<<<<<<<<<<<<<<<<[>>>>>>>>>>>>>>>>>>>>>>>>+>+<<<<<<<<<<<<<<<<<<<<<<<<<-]>>>>>>>>>>>>>>>>>>>>>>>>>[<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>>>>-]<[>+>+<<-]>>[<<+>>-]<<[>>+>+<<<-]>>>[<<<+>>>-]++++++++++<[>>+<<-]>>[<[>>+>+<<<-]>>>[<<<+>>>-]<[>+<<-[>>[-]>+<<<-]>>>[<<<+>>>-]<[<-[<<<->>>[-]]+>-]<-]<<<+>>]<[-]++++++++++<[>>>+<<<-]>>>[<<[<+>>+<-]>[<+>-]>-]<<[-]<[<->-]<[>+>+<<-]>>[<<+>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<<<<<<[>>]<-]<[<<]>[>[>>]<+<[<<]>-]>[>>]<<[-<<]>>>>>>>>>>>>>>>>>>>>>>>>++++[<++++++++++>-]<++++++++<[>>+>+<<<-]>>>[<<<+>>>-]<[<+>-]<.[-]<[-]<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]+[<->-]<<<<[-]>>>[<<<+>>>-]<[-]<+>]<-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]++++++++++.[-]<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]+[<+>-]<<<<[-]>>>[<<<+>>>-]<[-]<+>]<-]
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_solution5/mandelbrot.bf Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,148 @@
+// a Mandelbrot set generator in brainf___ written by Erik Bosman
+// (http://esoteric.sange.fi/brainfuck/utils/mandelbrot/)
+
+
++++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[
+>>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+
+<<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>>
+>+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>>
+>>>>>[-]+<<<<<<++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<+++++++[-[->>>
+>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[[-]>>>>>>[>>>>>
+>>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>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]<->>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<<
+<<<<<[->>>>>>>+<<<<<<<]<+<<<<<<<<<]>+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>
++>>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[-<<<<<<->>>>>>]+<
+<<<<<[->>>>>>->>[-<<<<<<<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+<<<<<<<<<<<<<<<<<[<<<<<<<
+<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>
+-<<[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>
+>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++
++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<<
+<<<<<]]>>>]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_solution5/sierpinski.bf Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,3 @@
+++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[
+->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
+]>.>+[>>]>+]
Binary file main_templates1/drumb.jar has changed
Binary file main_templates2/danube.jar has changed
Binary file main_templates3/re.jar has changed
Binary file main_templates4/knight2.jar has changed
Binary file main_templates4/knight3.jar has changed
Binary file main_templates5/bf.jar has changed
Binary file main_templates5/bfc.jar has changed
--- a/main_templates5/bfc.scala Mon Nov 02 02:31:44 2020 +0000
+++ b/main_templates5/bfc.scala Mon Nov 02 13:10:02 2020 +0000
@@ -111,7 +111,7 @@
// testcases
//
// optimise(load_bff("benchmark.bf")) // should have inserted 0's
-// optimise(load_bff("mandelbrot.bf")).length // => 11203
+// optimise(load_bff("mandelbrot.bf")).length // => 11205
//
// time_needed(1, run3(load_bff("benchmark.bf")))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/benchmark.bf Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,4 @@
+>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
+[>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
+++++++++[>++++++++++[>++++++++++[>++++++++++[>+
++++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++.
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/bf.scala Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,227 @@
+// Core Part about an Interpreter for
+// the Brainf***++ language
+//==============================================
+
+object CW10a {
+
+
+// representation of Bf memory
+
+type Mem = Map[Int, Int]
+
+
+// (1) Write a function that takes a file name as argument and
+// and requests the corresponding file from disk. It Returns the
+// content of the file as a String. If the file does not exists,
+// the function should Return the empty string.
+
+import io.Source
+import scala.util._
+
+def load_bff(name: String) : String =
+ Try(Source.fromFile(name)("ISO-8859-1").mkString).getOrElse("")
+
+
+// (2) Complete the functions for safely reading
+// and writing brainf***++ memory. Safely read should
+// Return the value stored in the Map for a given memory
+// pointer, provided it exists; otherwise it Returns 0. The
+// writing function generates a new Map with the
+// same data, except at the given memory pointer the
+// value v is stored.
+
+
+def sread(mem: Mem, mp: Int) : Int =
+ mem.getOrElse(mp, 0)
+
+def write(mem: Mem, mp: Int, v: Int) : Mem =
+ mem.updated(mp, v)
+
+
+// (3) Implement the two jumping instructions in the
+// brainf***++ language. In jumpRight, given a program and
+// a program counter move the program counter to the right
+// until after the *matching* ]-command. Similarly,
+// jumpLeft implements the move to the left to just after
+// the *matching* [-command.
+
+def jumpRight(prog: String, pc: Int, level: Int) : Int = {
+ if (prog.length <= pc) pc
+ else (prog(pc), level) match {
+ case (']', 0) => pc + 1
+ case (']', l) => jumpRight(prog, pc + 1, l - 1)
+ case ('[', l) => jumpRight(prog, pc + 1, l + 1)
+ case (_, l) => jumpRight(prog, pc + 1, l)
+ }
+}
+
+def jumpLeft(prog: String, pc: Int, level: Int) : Int = {
+ if (pc < 0) pc
+ else (prog(pc), level) match {
+ case ('[', 0) => pc + 1
+ case ('[', l) => jumpLeft(prog, pc - 1, l - 1)
+ case (']', l) => jumpLeft(prog, pc - 1, l + 1)
+ case (_, l) => jumpLeft(prog, pc - 1, l)
+ }
+}
+
+// test cases
+//jumpRight("""--[..+>--].>.++""", 3, 0) // => 10
+//jumpLeft("""--[..+>--].>.++""", 8, 0) // => 3
+//jumpRight("""--[..[+>]--].>.++""", 3, 0) // => 12
+//jumpRight("""--[..[[-]+>[.]]--].>.++""", 3, 0) // => 18
+//jumpRight("""--[..[[-]+>[.]]--.>.++""", 3, 0) // => 22 (outside)
+//jumpLeft("""[******]***""", 7, 0) // => -1 (outside)
+
+// (4) Complete the compute function that interprets (runs) a brainf***++
+// program: the arguments are a program (represented as a string), a program
+// counter, a memory counter and a brainf***++ memory. It Returns the
+// memory at the stage when the execution of the brainf***++ program
+// finishes. The interpretation finishes once the program counter
+// pc is pointing to something outside the program string.
+// If the pc points to a character inside the program, the pc,
+// memory pointer and memory need to be updated according to
+// rules of the brainf***++ language. Then, recursively, the compute
+// function continues with the command at the new program
+// counter.
+//
+// Implement the run function that calls compute with the program
+// counter and memory counter set to 0.
+
+def compute(prog: String, pc: Int, mp: Int, mem: Mem) : Mem = {
+ if (0 <= pc && pc < prog.length) {
+ val (new_pc, new_mp, new_mem) = prog(pc) match {
+ case '>' => (pc + 1, mp + 1, mem)
+ case '<' => (pc + 1, mp - 1, mem)
+ case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
+ case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
+ case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
+ //case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
+ //case ',' => (pc + 1, mp, write(mem, mp, scala.io.StdIn.readByte()))
+ case '[' =>
+ if (sread(mem, mp) == 0) (jumpRight(prog, pc + 1, 0), mp, mem) else (pc + 1, mp, mem)
+ case ']' =>
+ if (sread(mem, mp) != 0) (jumpLeft(prog, pc - 1, 0), mp, mem) else (pc + 1, mp, mem)
+
+ // new commands
+ case '@' => (pc + 1, mp, write(mem, sread(mem, mp), sread(mem, mp - 1)))
+ case '*' => (pc + 1, mp, write(mem, mp, sread(mem, mp) * sread(mem, mp -1)))
+ case '#' => { println(s"${sread(mem, mp)}"); (pc + 1, mp, mem) }
+
+ case _ => (pc + 1, mp, mem)
+ }
+ compute(prog, new_pc, new_mp, new_mem)
+ }
+ else mem
+}
+
+def run(prog: String, m: Mem = Map()) = compute(prog, 0, 0, m)
+
+
+
+
+
+// some sample bf/bf++-programs collected from the Internet
+//==========================================================
+
+
+// some contrived (small) programs
+//---------------------------------
+
+// clears the 0-cell
+//run("[-]", Map(0 -> 100)) // Map will be 0 -> 0
+
+// moves content of the 0-cell to 1-cell
+//run("[->+<]", Map(0 -> 10)) // Map will be 0 -> 0, 1 -> 10
+
+
+// copies content of the 0-cell to 2-cell and 4-cell
+//run("[>>+>>+<<<<-]", Map(0 -> 42)) // Map(0 -> 0, 2 -> 42, 4 -> 42)
+
+
+// prints out numbers 0 to 9
+//run("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""")
+
+// bf++ program calculating the cube-function, 10 * 10 * 10 = 1000
+//run("""++++++++++#>+***#""") // Map(0 -> 10, 1 -> 1000)
+
+
+// bf++ program copies 3 from 0-cell to to cells 1, 4, 5, 6 and 7
+// (note that because of how the program wprks cell 1 will contain 7)
+//run("""+++>+@+@+@+@+@""") // Map(0 -> 3, 1 -> 7, 4 -> 3, 5 -> 3, 6 -> 3, 7 -> 3)
+
+
+
+// some more "useful" programs
+//-----------------------------
+
+// hello world program 1
+//run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
+// ..+++.>>.<-.<.+++.------.--------.>>+.>++.""")
+
+// hello world program 2
+//run("""++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>+
+// +.<<+++++++++++++++.>.+++.------.--------.>+.>.""")
+
+// hello world program 3
+//run("""+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..
+// +++.>-.------------.<++++++++.--------.+++.------.--------.>+.""")
+
+
+// draws the Sierpinski triangle
+//run(load_bff("sierpinski.bf"))
+
+
+//fibonacci numbers below 100
+//run("""+++++++++++
+// >+>>>>++++++++++++++++++++++++++++++++++++++++++++
+// >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
+// +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
+// <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
+// -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
+// >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
+// +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
+// ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
+// <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
+// [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]""")
+
+//outputs the square numbers up to 10000
+//run("""++++[>+++++<-]>[<+++++>-]+<+[>[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+
+// >>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]
+// <<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]""")
+
+
+// calculates 2 to the power of 6
+//(example from a C-to-BF compiler at https://github.com/elikaski/BF-it)
+//run(""">>[-]>[-]++>[-]++++++><<<>>>>[-]+><>[-]<<[-]>[>+<<+>-]>[<+>-]
+// <><[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-]
+// <[>+>+<<-]>[<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<[[-]>[-]<<[>+>
+// +<<-]>>[<<+>>-][-]>[-]<<<<<[>>>>+>+<<<<<-]>>>>>[<<<<<+>>>>>-]
+// <<>>[-]>[-]<<<[>>>+<<<-]>>>[<<[<+>>+<-]>[<+>-]>-]<<<>[-]<<[-]
+// >[>+<<+>-]>[<+>-]<><[-]>[-]<<<[>>+>+<<<-]>>>-[<<<+>>>-]<[-]>[-]
+// <<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-]<[>+>+<<-]>
+// [<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<][-]>[-]<<[>+>+<<-]>>[<<+>
+// >-]<<<<<[-]>>>>[<<<<+>>>>-]<<<<><>[-]<<[-]>[>+<<+>-]>[<+>-]<>
+// <[-]>[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-]<<>>[-]>[-]>[-]>[-]>[-]>
+// [-]>[-]>[-]>[-]>[-]<<<<<<<<<<>>++++++++++<<[->+>-[>+>>]>[+[-<+
+// >]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<
+// ]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++
+// ++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<<><<<""")
+
+
+
+// a Mandelbrot set generator in brainf*** written by Erik Bosman
+// (http://esoteric.sange.fi/brainfuck/utils/mandelbrot/)
+//
+//run(load_bff("mandelbrot.bf"))
+
+
+// a benchmark program (counts down from 'Z' to 'A')
+//
+//run(load_bff("benchmark.bf"))
+
+// calculates the Collatz series for numbers from 1 to 30
+//
+//run(load_bff("collatz.bf"))
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/bf_test.sh Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,138 @@
+#!/bin/bash
+set -euo pipefail
+
+out=${1:-output}
+
+echo -e "" > $out
+
+echo -e "Below is the feedback for your submission of CW 10." >> $out
+echo -e "" >> $out
+
+
+# compilation tests
+
+function scala_compile {
+ (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
+}
+
+# functional tests
+
+function scala_assert {
+ (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
+}
+
+# purity test
+
+function scala_vars {
+ (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
+}
+
+
+
+# compilation test
+echo -e "bf.scala runs?" >> $out
+
+if (scala_compile bf.scala)
+then
+ echo -e " --> success" >> $out
+ tsts1=$(( 0 ))
+else
+ echo -e " --> SCALA DID NOT RUN BF.SCALA\n" >> $out
+ tsts1=$(( 1 ))
+fi
+
+
+# var, return, ListBuffer test
+#
+
+if [ $tsts1 -eq 0 ]
+then
+ echo -e "bf.scala does not contain vars, returns etc?" >> $out
+
+ if (scala_vars bf.scala)
+ then
+ echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out
+ tsts1=$(( 1 ))
+ else
+ echo -e " --> success" >> $out
+ tsts1=$(( 0 ))
+ fi
+fi
+
+
+
+### bf tests
+
+if [ $tsts1 -eq 0 ]
+then
+ echo -e " load_bff(\"benchmark.bf\").length == 188" >> $out
+ echo -e " load_bff(\"foobar.bf\") == \"\"" >> $out
+
+ if (scala_assert "bf.scala" "bf_test1.scala")
+ then
+ echo -e " --> success" >> $out
+ else
+ echo -e " --> \n ONE TEST FAILED\n" >> $out
+ fi
+fi
+
+if [ $tsts1 -eq 0 ]
+then
+ echo -e " sread(Map(), 2) == 0" >> $out
+ echo -e " sread(Map(2 -> 1), 2) == 1" >> $out
+ echo -e " write(Map(), 1, 2) == Map(1 -> 2)" >> $out
+ echo -e " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" >> $out
+
+ if (scala_assert "bf.scala" "bf_test2.scala")
+ then
+ echo -e " --> success" >> $out
+ else
+ echo -e " --> \n ONE TEST FAILED\n" >> $out
+ fi
+fi
+
+
+
+if [ $tsts1 -eq 0 ]
+then
+ echo -e " jumpRight(\"[xxxxxx]xxx\", 1, 0) == 8" >> $out
+ echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" >> $out
+ echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" >> $out
+ echo -e " jumpRight(\"[xx[xxx]xxx\", 1, 0) == 11" >> $out
+ echo -e " jumpRight(\"[x[][]x]xxx\", 1, 0) == 8" >> $out
+ echo -e " jumpLeft(\"[xxxxxx]xxx\", 6, 0) == 1" >> $out
+ echo -e " jumpLeft(\"[xxxxxx]xxx\", 7, 0) == -1" >> $out
+ echo -e " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" >> $out
+
+ if (scala_assert "bf.scala" "bf_test3.scala")
+ then
+ echo -e " --> success" >> $out
+ else
+ echo -e " --> \n ONE TEST FAILED\n" >> $out
+ fi
+fi
+
+
+
+if [ $tsts1 -eq 0 ]
+then
+ echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" >> $out
+ echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" >> $out
+ echo -e " run(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" >> $out
+ echo -e " run(\"++++++++++#>+***#\") == Map(0 -> 10, 1 -> 1000))" >> $out
+ echo -e " run(\"+++>+@+@+@+@+@\") == Map(0 -> 3, 1 -> 7, 4 -> 3, 5 -> 3, 6 -> 3, 7 -> 3)" >> $out
+
+ echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" >> $out
+ echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" >> $out
+
+ if (scala_assert "bf.scala" "bf_test4.scala")
+ then
+ echo -e " --> success" >> $out
+ else
+ echo -e " --> \n ONE TEST FAILED\n" >> $out
+ fi
+fi
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/bf_test1.scala Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,4 @@
+import CW10a._
+
+assert(load_bff("benchmark.bf").length == 188)
+assert(load_bff("foobar.bf") == "")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/bf_test2.scala Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,6 @@
+import CW10a._
+
+assert(sread(Map(), 2) == 0)
+assert(sread(Map(2 -> 1), 2) == 1)
+assert(write(Map(), 1, 2) == Map(1 -> 2))
+assert(write(Map(1 -> 0), 1, 2) == Map(1 -> 2))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/bf_test3.scala Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,10 @@
+import CW10a._
+
+assert(jumpRight("[xxxxxx]xxx", 1, 0) == 8)
+assert(jumpRight("[xx[x]x]xxx", 1, 0) == 8)
+assert(jumpRight("[xx[x]x]xxx", 1, 0) == 8)
+assert(jumpRight("[xx[xxx]xxx", 1, 0) == 11)
+assert(jumpRight("[x[][]x]xxx", 1, 0) == 8)
+assert(jumpLeft("[xxxxxx]xxx", 6, 0) == 1)
+assert(jumpLeft("[xxxxxx]xxx", 7, 0) == -1)
+assert(jumpLeft("[x[][]x]xxx", 6, 0) == 1)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/bf_test4.scala Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,14 @@
+import CW10a._
+
+assert(run("[-]", Map(0 -> 100)) == Map(0 -> 0))
+assert(run("[->+<]", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10))
+assert(run("[>>+>>+<<<<-]", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42))
+assert(run("++++++++++#>+***#") == Map(0 -> 10, 1 -> 1000))
+assert(run("+++>+@+@+@+@+@") == Map(0 -> 3, 1 -> 7, 4 -> 3, 5 -> 3, 6 -> 3, 7 -> 3))
+
+
+
+val hw_urban = """+++++[->++++++++++<]>--<+++[->>++++++++++
+ <<]>>++<<----------[+>.>.<+<]"""
+assert(run(hw_urban) == Map(0 -> 0, 1 -> 58, 2 -> 32))
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/bf_test5.scala Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,5 @@
+import CW10b._
+
+assert(jtable("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""") ==
+ Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6))
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/bf_test6.scala Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,7 @@
+import CW10b._
+
+//println(optimise(load_bff("benchmark.bf")).length)
+//println(optimise(load_bff("mandelbrot.bf")).length)
+
+assert(optimise(load_bff("benchmark.bf")).length == 181)
+assert(optimise(load_bff("mandelbrot.bf")).length == 11205)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/bf_test7.scala Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,7 @@
+import CW10b._
+
+//println(combine(optimise(load_bff("benchmark.bf"))).length)
+//println(combine(optimise(load_bff("mandelbrot.bf"))).length)
+
+assert(combine(optimise(load_bff("benchmark.bf"))).length == 134)
+assert(combine(optimise(load_bff("mandelbrot.bf"))).length == 6511)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/bfc.scala Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,312 @@
+// Part 2 about a "Compiler" for the Brainf*** language
+//======================================================
+
+object CW10b {
+
+// !!! Copy any function you need from file bf.scala !!!
+//
+// If you need any auxiliary function, feel free to
+// implement it, but do not make any changes to the
+// templates below.
+
+
+def time_needed[T](n: Int, code: => T) = {
+ val start = System.nanoTime()
+ for (i <- 0 until n) code
+ val end = System.nanoTime()
+ (end - start)/(n * 1.0e9)
+}
+
+type Mem = Map[Int, Int]
+
+
+import io.Source
+import scala.util._
+
+def load_bff(name: String) : String =
+ Try(Source.fromFile(name)("ISO-8859-1").mkString).getOrElse("")
+
+def sread(mem: Mem, mp: Int) : Int =
+ mem.getOrElse(mp, 0)
+
+def write(mem: Mem, mp: Int, v: Int) : Mem =
+ mem.updated(mp, v)
+
+def jumpRight(prog: String, pc: Int, level: Int) : Int = {
+ if (prog.length <= pc) pc
+ else (prog(pc), level) match {
+ case (']', 0) => pc + 1
+ case (']', l) => jumpRight(prog, pc + 1, l - 1)
+ case ('[', l) => jumpRight(prog, pc + 1, l + 1)
+ case (_, l) => jumpRight(prog, pc + 1, l)
+ }
+}
+
+def jumpLeft(prog: String, pc: Int, level: Int) : Int = {
+ if (pc < 0) pc
+ else (prog(pc), level) match {
+ case ('[', 0) => pc + 1
+ case ('[', l) => jumpLeft(prog, pc - 1, l - 1)
+ case (']', l) => jumpLeft(prog, pc - 1, l + 1)
+ case (_, l) => jumpLeft(prog, pc - 1, l)
+ }
+}
+
+def compute(prog: String, pc: Int, mp: Int, mem: Mem) : Mem = {
+ if (0 <= pc && pc < prog.length) {
+ val (new_pc, new_mp, new_mem) = prog(pc) match {
+ case '>' => (pc + 1, mp + 1, mem)
+ case '<' => (pc + 1, mp - 1, mem)
+ case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
+ case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
+ case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
+ case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
+ case '[' =>
+ if (sread(mem, mp) == 0) (jumpRight(prog, pc + 1, 0), mp, mem) else (pc + 1, mp, mem)
+ case ']' =>
+ if (sread(mem, mp) != 0) (jumpLeft(prog, pc - 1, 0), mp, mem) else (pc + 1, mp, mem)
+ case _ => (pc + 1, mp, mem)
+ }
+ compute(prog, new_pc, new_mp, new_mem)
+ }
+ else mem
+}
+
+def run(prog: String, m: Mem = Map()) = compute(prog, 0, 0, m)
+
+
+// The baseline to what we can compare our "compiler"
+// implemented below. It should require something like
+// 60 seconds for the calculation on my laptop
+//
+//time_needed(1, run(load_bff("benchmark.bf")))
+
+
+
+// DEBUGGING INFORMATION!!!
+//
+// Compiler, even real ones, are fiedishly difficult to get
+// to prduce correct code. The point is that for example for
+// the sierpinski program, they need to still generate code
+// that displays such a triangle. If yes, then one usually
+// can take comfort that all is well. If not, then something
+// went wrong during the optimisations.
+
+
+
+// (5) Write a function jtable that precomputes the "jump
+// table" for a bf-program. This function takes a bf-program
+// as an argument and Returns a Map[Int, Int]. The
+// purpose of this map is to record the information
+// that given on the position pc is a '[' or a ']',
+// then to which pc-position do we need to jump next?
+//
+// For example for the program
+//
+// "+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]"
+//
+// we obtain the map
+//
+// Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)
+//
+// This states that for the '[' on position 5, we need to
+// jump to position 20, which is just after the corresponding ']'.
+// Similarly, for the ']' on position 19, we need to jump to
+// position 6, which is just after the '[' on position 5, and so
+// on. The idea is to not calculate this information each time
+// we hit a bracket, but just look up this information in the
+// jtable. You can use the jumpLeft and jumpRight functions
+// from Part 1 for calculating the jtable.
+//
+// Then adapt the compute and run functions from Part 1 in order
+// to take advantage of the information stored in the jtable.
+// This means whenever jumpLeft and jumpRight was called previously,
+// you should look up the jump address in the jtable.
+
+
+def jtable(pg: String) : Map[Int, Int] =
+ (0 until pg.length).collect { pc => pg(pc) match {
+ case '[' => (pc -> jumpRight(pg, pc + 1, 0))
+ case ']' => (pc -> jumpLeft(pg, pc - 1, 0))
+ }}.toMap
+
+
+// testcase
+// jtable("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""")
+// => Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)
+
+
+def compute2(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
+ if (0 <= pc && pc < pg.length) {
+ val (new_pc, new_mp, new_mem) = pg(pc) match {
+ case '>' => (pc + 1, mp + 1, mem)
+ case '<' => (pc + 1, mp - 1, mem)
+ case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
+ case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
+ case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
+ case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
+ case '[' =>
+ if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
+ case ']' =>
+ if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
+ case _ => (pc + 1, mp, mem)
+ }
+ compute2(pg, tb, new_pc, new_mp, new_mem)
+ }
+ else mem
+}
+
+
+def run2(pg: String, m: Mem = Map()) =
+ compute2(pg, jtable(pg), 0, 0, m)
+
+//time_needed(1, run2(load_bff("benchmark.bf")))
+
+
+
+// (6) Write a function optimise which deletes "dead code" (everything
+// that is not a bf-command) and also replaces substrings of the form
+// [-] by a new command 0. The idea is that the loop [-] just resets the
+// memory at the current location to 0. In the compute3 and run3 functions
+// below you implement this command by writing the number 0 to mem(mp),
+// 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
+// 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 compute3(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
+ if (0 <= pc && pc < pg.length) {
+ val (new_pc, new_mp, new_mem) = pg(pc) match {
+ case '0' => (pc + 1, mp, write(mem, mp, 0))
+ case '>' => (pc + 1, mp + 1, mem)
+ case '<' => (pc + 1, mp - 1, mem)
+ case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
+ case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
+ case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
+ case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
+ case '[' =>
+ if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
+ case ']' =>
+ if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
+ case _ => (pc + 1, mp, mem)
+ }
+ compute3(pg, tb, new_pc, new_mp, new_mem)
+ }
+ else mem
+}
+
+def run3(pg: String, m: Mem = Map()) = {
+ val pg_opt = optimise(pg)
+ compute3(pg_opt, jtable(pg_opt), 0, 0, m)
+}
+
+
+// testcases
+
+//optimise(load_bff("benchmark.bf")) // should have inserted 0's
+//optimise(load_bff("benchmark.bf")).length // => 181
+//optimise(load_bff("mandelbrot.bf")).length // => 11203
+
+//time_needed(1, run3(load_bff("benchmark.bf")))
+
+
+
+// (7) Write a function combine which replaces sequences
+// of repated increment and decrement commands by appropriate
+// two-character commands. For example for sequences of +
+//
+// orig bf-cmds | replacement
+// ------------------------------
+// + | +A
+// ++ | +B
+// +++ | +C
+// |
+// ... |
+// |
+// +++....+++ | +Z
+// (where length = 26)
+//
+// Similar for the bf-command -, > and <. All other commands should
+// be unaffected by this change.
+//
+// Adapt the compute4 and run4 functions such that they can deal
+// appropriately with such two-character commands.
+
+def splice(cs: List[Char], acc: List[(Char, Int)]) : List[(Char, Int)] = (cs, acc) match {
+ case (Nil, acc) => acc
+ case ('[' :: cs, acc) => splice(cs, ('[', 1) :: acc)
+ case (']' :: cs, acc) => splice(cs, (']', 1) :: acc)
+ case ('.' :: cs, acc) => splice(cs, ('.', 1) :: acc)
+ case (',' :: cs, acc) => splice(cs, (',', 1) :: acc)
+ case ('0' :: cs, acc) => splice(cs, ('0', 1) :: acc)
+ case (c :: cs, Nil) => splice(cs, List((c, 1)))
+ case (c :: cs, (d, n) :: acc) =>
+ if (c == d && n < 26) splice(cs, (c, n + 1) :: acc)
+ else splice(cs, (c, 1) :: (d, n) :: acc)
+}
+
+def spl(s: String) = splice(s.toList, Nil).reverse
+
+//spl(load_bff("benchmark.bf"))
+
+def combine(s: String) : String = {
+ (for ((c, n) <- spl(s)) yield c match {
+ case '>' => List('>', (n + '@').toChar)
+ case '<' => List('<', (n + '@').toChar)
+ case '+' => List('+', (n + '@').toChar)
+ case '-' => List('-', (n + '@').toChar)
+ case _ => List(c)
+ }).flatten.mkString
+}
+
+
+//combine(load_bff("benchmark.bf"))
+
+def compute4(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
+ if (0 <= pc && pc < pg.length) {
+ val (new_pc, new_mp, new_mem) = pg(pc) match {
+ case '0' => (pc + 1, mp, write(mem, mp, 0))
+ case '>' => (pc + 2, mp + (pg(pc + 1) - '@'), mem)
+ case '<' => (pc + 2, mp - (pg(pc + 1) - '@'), mem)
+ case '+' => (pc + 2, mp, write(mem, mp, sread(mem, mp) + (pg(pc + 1) - '@')))
+ case '-' => (pc + 2, mp, write(mem, mp, sread(mem, mp) - (pg(pc + 1) - '@')))
+ case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
+ case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
+ case '[' =>
+ if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
+ case ']' =>
+ if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
+ case _ => (pc + 1, mp, mem)
+ }
+ compute4(pg, tb, new_pc, new_mp, new_mem)
+ }
+ else mem
+}
+
+def run4(pg: String, m: Mem = Map()) = {
+ val pg_opt = combine(optimise(pg))
+ compute4(pg_opt, jtable(pg_opt), 0, 0, m)
+}
+
+// testcases
+//combine(optimise(load_bff("benchmark.bf"))) // => """>A+B[<A+M>A-A]<A[[....."""
+//combine(optimise(load_bff("benchmark.bf"))).length // => 134
+//combine(optimise(load_bff("mandelbrot.bf"))).length // => 6509
+
+//time_needed(1, run4(load_bff("benchmark.bf")))
+
+//time_needed(1, run(load_bff("sierpinski.bf")))
+//time_needed(1, run4(load_bff("sierpinski.bf")))
+
+//time_needed(1, run4(load_bff("mandelbrot.bf")))
+
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/bfc_test.sh Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,107 @@
+#!/bin/bash
+set -e
+
+out=${1:-output}
+
+echo -e "" > $out
+
+echo -e "Below is the feedback for your submission of CW 10, Part 2." >> $out
+echo -e "" >> $out
+
+# compilation tests
+
+function scala_compile {
+ (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
+}
+
+# functional tests
+
+function scala_assert {
+ (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
+}
+
+# purity test
+
+function scala_vars {
+ (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
+}
+
+
+
+
+# compilation test
+echo -e "bfc.scala runs?" >> $out
+
+if (scala_compile bfc.scala)
+then
+ echo -e " --> success" >> $out
+ tsts1=$(( 0 ))
+else
+ echo -e " --> --> SCALA DID NOT RUN BFC.SCALA\n" >> $out
+ tsts1=$(( 1 ))
+fi
+
+
+# var, return, ListBuffer test
+#
+if [ $tsts1 -eq 0 ]
+then
+ echo -e "bfc.scala does not contain vars, returns etc?" >> $out
+
+ if (scala_vars bfc.scala)
+ then
+ echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out
+ tsts1=$(( 1 ))
+ else
+ echo -e " --> success" >> $out
+ tsts1=$(( 0 ))
+ fi
+fi
+
+### bfc tests
+
+if [ $tsts1 -eq 0 ]
+then
+ echo -e " jtable(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\") ==" >> $out
+ echo -e " Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" >> $out
+
+ if (scala_assert "bfc.scala" "bf_test5.scala")
+ then
+ echo -e " --> success" >> $out
+ else
+ echo -e " --> \n ONE TEST FAILED\n" >> $out
+ fi
+fi
+
+
+
+if [ $tsts1 -eq 0 ]
+then
+ echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out
+ echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11205" >> $out
+
+ if (scala_assert "bfc.scala" "bf_test6.scala")
+ then
+ echo -e " --> success" >> $out
+ else
+ echo -e " --> \n ONE TEST FAILED\n" >> $out
+ fi
+fi
+
+
+
+if [ $tsts1 -eq 0 ]
+then
+ echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" >> $out
+ echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6511" >> $out
+
+ if (scala_assert "bfc.scala" "bf_test7.scala")
+ then
+ echo -e " --> success" >> $out
+ else
+ echo -e " --> \n ONE TEST FAILED\n" >> $out
+ fi
+fi
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/mandelbrot.bf Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,148 @@
+// a Mandelbrot set generator in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<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++
++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<<
+<<<<<]]>>>]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing5/sierpinski.bf Mon Nov 02 13:10:02 2020 +0000
@@ -0,0 +1,3 @@
+++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[
+->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
+]>.>+[>>]>+]
--- a/mk_jars Mon Nov 02 02:31:44 2020 +0000
+++ b/mk_jars Mon Nov 02 13:10:02 2020 +0000
@@ -1,13 +1,16 @@
#!/bin/sh
set -e
-for sd in solutions*; do
+subdirs=${1:-"pre_solution1 pre_solution2 pre_solution3 pre_solution4 main_solution1 main_solution2 main_solution3 main_solution4 main_solution5"}
+
+for sd in $subdirs; do
cd $sd
for fl in *.scala; do
- echo "$fl compiled to ${fl%".scala"}.jar"
- scalac -d ${fl%".scala"}.jar $fl
- echo "copied to ../templates${sd#"solutions"}/"
- cp ${fl%".scala"}.jar ../templates${sd#"solutions"}/
+ echo "$sd/$fl"
+ echo "copy to ${sd/solution/templates}/${fl%.scala}.jar"
+ scalac -d ${fl%.scala}.jar $fl
+ cp ${fl%.scala}.jar "../${sd/solution/templates}"
+ hg add "../${sd/solution/templates}/${fl%.scala}.jar"
done
cd ..
done
Binary file pre_solution1/collatz.jar has changed
Binary file pre_solution2/docdiff.jar has changed
Binary file pre_solution3/postfix.jar has changed
Binary file pre_solution3/postfix2.jar has changed
Binary file pre_templates1/collatz.jar has changed
Binary file pre_templates2/docdiff.jar has changed
Binary file pre_templates3/postfix.jar has changed
Binary file pre_templates3/postfix2.jar has changed
Binary file pre_templates4/knight1.jar has changed
--- a/solutions5/benchmark.bf Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
->++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
-[>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
-++++++++[>++++++++++[>++++++++++[>++++++++++[>+
-+++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++.
\ No newline at end of file
Binary file solutions5/bf.jar has changed
--- a/solutions5/bf.scala Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,227 +0,0 @@
-// Core Part about an Interpreter for
-// the Brainf***++ language
-//==============================================
-
-object CW10a {
-
-
-// representation of Bf memory
-
-type Mem = Map[Int, Int]
-
-
-// (1) Write a function that takes a file name as argument and
-// and requests the corresponding file from disk. It Returns the
-// content of the file as a String. If the file does not exists,
-// the function should Return the empty string.
-
-import io.Source
-import scala.util._
-
-def load_bff(name: String) : String =
- Try(Source.fromFile(name)("ISO-8859-1").mkString).getOrElse("")
-
-
-// (2) Complete the functions for safely reading
-// and writing brainf***++ memory. Safely read should
-// Return the value stored in the Map for a given memory
-// pointer, provided it exists; otherwise it Returns 0. The
-// writing function generates a new Map with the
-// same data, except at the given memory pointer the
-// value v is stored.
-
-
-def sread(mem: Mem, mp: Int) : Int =
- mem.getOrElse(mp, 0)
-
-def write(mem: Mem, mp: Int, v: Int) : Mem =
- mem.updated(mp, v)
-
-
-// (3) Implement the two jumping instructions in the
-// brainf***++ language. In jumpRight, given a program and
-// a program counter move the program counter to the right
-// until after the *matching* ]-command. Similarly,
-// jumpLeft implements the move to the left to just after
-// the *matching* [-command.
-
-def jumpRight(prog: String, pc: Int, level: Int) : Int = {
- if (prog.length <= pc) pc
- else (prog(pc), level) match {
- case (']', 0) => pc + 1
- case (']', l) => jumpRight(prog, pc + 1, l - 1)
- case ('[', l) => jumpRight(prog, pc + 1, l + 1)
- case (_, l) => jumpRight(prog, pc + 1, l)
- }
-}
-
-def jumpLeft(prog: String, pc: Int, level: Int) : Int = {
- if (pc < 0) pc
- else (prog(pc), level) match {
- case ('[', 0) => pc + 1
- case ('[', l) => jumpLeft(prog, pc - 1, l - 1)
- case (']', l) => jumpLeft(prog, pc - 1, l + 1)
- case (_, l) => jumpLeft(prog, pc - 1, l)
- }
-}
-
-// test cases
-//jumpRight("""--[..+>--].>.++""", 3, 0) // => 10
-//jumpLeft("""--[..+>--].>.++""", 8, 0) // => 3
-//jumpRight("""--[..[+>]--].>.++""", 3, 0) // => 12
-//jumpRight("""--[..[[-]+>[.]]--].>.++""", 3, 0) // => 18
-//jumpRight("""--[..[[-]+>[.]]--.>.++""", 3, 0) // => 22 (outside)
-//jumpLeft("""[******]***""", 7, 0) // => -1 (outside)
-
-// (4) Complete the compute function that interprets (runs) a brainf***++
-// program: the arguments are a program (represented as a string), a program
-// counter, a memory counter and a brainf***++ memory. It Returns the
-// memory at the stage when the execution of the brainf***++ program
-// finishes. The interpretation finishes once the program counter
-// pc is pointing to something outside the program string.
-// If the pc points to a character inside the program, the pc,
-// memory pointer and memory need to be updated according to
-// rules of the brainf***++ language. Then, recursively, the compute
-// function continues with the command at the new program
-// counter.
-//
-// Implement the run function that calls compute with the program
-// counter and memory counter set to 0.
-
-def compute(prog: String, pc: Int, mp: Int, mem: Mem) : Mem = {
- if (0 <= pc && pc < prog.length) {
- val (new_pc, new_mp, new_mem) = prog(pc) match {
- case '>' => (pc + 1, mp + 1, mem)
- case '<' => (pc + 1, mp - 1, mem)
- case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
- case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
- case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
- //case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
- //case ',' => (pc + 1, mp, write(mem, mp, scala.io.StdIn.readByte()))
- case '[' =>
- if (sread(mem, mp) == 0) (jumpRight(prog, pc + 1, 0), mp, mem) else (pc + 1, mp, mem)
- case ']' =>
- if (sread(mem, mp) != 0) (jumpLeft(prog, pc - 1, 0), mp, mem) else (pc + 1, mp, mem)
-
- // new commands
- case '@' => (pc + 1, mp, write(mem, sread(mem, mp), sread(mem, mp - 1)))
- case '*' => (pc + 1, mp, write(mem, mp, sread(mem, mp) * sread(mem, mp -1)))
- case '#' => { println(s"${sread(mem, mp)}"); (pc + 1, mp, mem) }
-
- case _ => (pc + 1, mp, mem)
- }
- compute(prog, new_pc, new_mp, new_mem)
- }
- else mem
-}
-
-def run(prog: String, m: Mem = Map()) = compute(prog, 0, 0, m)
-
-
-
-
-
-// some sample bf/bf++-programs collected from the Internet
-//==========================================================
-
-
-// some contrived (small) programs
-//---------------------------------
-
-// clears the 0-cell
-//run("[-]", Map(0 -> 100)) // Map will be 0 -> 0
-
-// moves content of the 0-cell to 1-cell
-//run("[->+<]", Map(0 -> 10)) // Map will be 0 -> 0, 1 -> 10
-
-
-// copies content of the 0-cell to 2-cell and 4-cell
-//run("[>>+>>+<<<<-]", Map(0 -> 42)) // Map(0 -> 0, 2 -> 42, 4 -> 42)
-
-
-// prints out numbers 0 to 9
-//run("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""")
-
-// bf++ program calculating the cube-function, 10 * 10 * 10 = 1000
-//run("""++++++++++#>+***#""") // Map(0 -> 10, 1 -> 1000)
-
-
-// bf++ program copies 3 from 0-cell to to cells 1, 4, 5, 6 and 7
-// (note that because of how the program wprks cell 1 will contain 7)
-//run("""+++>+@+@+@+@+@""") // Map(0 -> 3, 1 -> 7, 4 -> 3, 5 -> 3, 6 -> 3, 7 -> 3)
-
-
-
-// some more "useful" programs
-//-----------------------------
-
-// hello world program 1
-//run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
-// ..+++.>>.<-.<.+++.------.--------.>>+.>++.""")
-
-// hello world program 2
-//run("""++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>+
-// +.<<+++++++++++++++.>.+++.------.--------.>+.>.""")
-
-// hello world program 3
-//run("""+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..
-// +++.>-.------------.<++++++++.--------.+++.------.--------.>+.""")
-
-
-// draws the Sierpinski triangle
-//run(load_bff("sierpinski.bf"))
-
-
-//fibonacci numbers below 100
-//run("""+++++++++++
-// >+>>>>++++++++++++++++++++++++++++++++++++++++++++
-// >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
-// +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
-// <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
-// -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
-// >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
-// +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
-// ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
-// <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
-// [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]""")
-
-//outputs the square numbers up to 10000
-//run("""++++[>+++++<-]>[<+++++>-]+<+[>[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+
-// >>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]
-// <<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]""")
-
-
-// calculates 2 to the power of 6
-//(example from a C-to-BF compiler at https://github.com/elikaski/BF-it)
-//run(""">>[-]>[-]++>[-]++++++><<<>>>>[-]+><>[-]<<[-]>[>+<<+>-]>[<+>-]
-// <><[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-]
-// <[>+>+<<-]>[<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<[[-]>[-]<<[>+>
-// +<<-]>>[<<+>>-][-]>[-]<<<<<[>>>>+>+<<<<<-]>>>>>[<<<<<+>>>>>-]
-// <<>>[-]>[-]<<<[>>>+<<<-]>>>[<<[<+>>+<-]>[<+>-]>-]<<<>[-]<<[-]
-// >[>+<<+>-]>[<+>-]<><[-]>[-]<<<[>>+>+<<<-]>>>-[<<<+>>>-]<[-]>[-]
-// <<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-]<[>+>+<<-]>
-// [<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<][-]>[-]<<[>+>+<<-]>>[<<+>
-// >-]<<<<<[-]>>>>[<<<<+>>>>-]<<<<><>[-]<<[-]>[>+<<+>-]>[<+>-]<>
-// <[-]>[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-]<<>>[-]>[-]>[-]>[-]>[-]>
-// [-]>[-]>[-]>[-]>[-]<<<<<<<<<<>>++++++++++<<[->+>-[>+>>]>[+[-<+
-// >]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<
-// ]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++
-// ++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<<><<<""")
-
-
-
-// a Mandelbrot set generator in brainf*** written by Erik Bosman
-// (http://esoteric.sange.fi/brainfuck/utils/mandelbrot/)
-//
-//run(load_bff("mandelbrot.bf"))
-
-
-// a benchmark program (counts down from 'Z' to 'A')
-//
-//run(load_bff("benchmark.bf"))
-
-// calculates the Collatz series for numbers from 1 to 30
-//
-//run(load_bff("collatz.bf"))
-
-}
Binary file solutions5/bfc.jar has changed
--- a/solutions5/bfc.scala Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,317 +0,0 @@
-// Part 2 about a "Compiler" for the Brainf*** language
-//======================================================
-
-object CW10b {
-
-// !!! Copy any function you need from file bf.scala !!!
-//
-// If you need any auxiliary function, feel free to
-// implement it, but do not make any changes to the
-// templates below.
-
-
-def time_needed[T](n: Int, code: => T) = {
- val start = System.nanoTime()
- for (i <- 0 until n) code
- val end = System.nanoTime()
- (end - start)/(n * 1.0e9)
-}
-
-type Mem = Map[Int, Int]
-
-
-import io.Source
-import scala.util._
-
-def load_bff(name: String) : String =
- Try(Source.fromFile(name)("ISO-8859-1").mkString).getOrElse("")
-
-def sread(mem: Mem, mp: Int) : Int =
- mem.getOrElse(mp, 0)
-
-def write(mem: Mem, mp: Int, v: Int) : Mem =
- mem.updated(mp, v)
-
-def jumpRight(prog: String, pc: Int, level: Int) : Int = {
- if (prog.length <= pc) pc
- else (prog(pc), level) match {
- case (']', 0) => pc + 1
- case (']', l) => jumpRight(prog, pc + 1, l - 1)
- case ('[', l) => jumpRight(prog, pc + 1, l + 1)
- case (_, l) => jumpRight(prog, pc + 1, l)
- }
-}
-
-def jumpLeft(prog: String, pc: Int, level: Int) : Int = {
- if (pc < 0) pc
- else (prog(pc), level) match {
- case ('[', 0) => pc + 1
- case ('[', l) => jumpLeft(prog, pc - 1, l - 1)
- case (']', l) => jumpLeft(prog, pc - 1, l + 1)
- case (_, l) => jumpLeft(prog, pc - 1, l)
- }
-}
-
-def compute(prog: String, pc: Int, mp: Int, mem: Mem) : Mem = {
- if (0 <= pc && pc < prog.length) {
- val (new_pc, new_mp, new_mem) = prog(pc) match {
- case '>' => (pc + 1, mp + 1, mem)
- case '<' => (pc + 1, mp - 1, mem)
- case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
- case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
- case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
- case '[' =>
- if (sread(mem, mp) == 0) (jumpRight(prog, pc + 1, 0), mp, mem) else (pc + 1, mp, mem)
- case ']' =>
- if (sread(mem, mp) != 0) (jumpLeft(prog, pc - 1, 0), mp, mem) else (pc + 1, mp, mem)
- case _ => (pc + 1, mp, mem)
- }
- compute(prog, new_pc, new_mp, new_mem)
- }
- else mem
-}
-
-def run(prog: String, m: Mem = Map()) = compute(prog, 0, 0, m)
-
-
-// The baseline to what we can compare our "compiler"
-// implemented below. It should require something like
-// 60 seconds for the calculation on my laptop
-//
-//time_needed(1, run(load_bff("benchmark.bf")))
-
-
-
-// DEBUGGING INFORMATION!!!
-//
-// Compiler, even real ones, are fiedishly difficult to get
-// to prduce correct code. The point is that for example for
-// the sierpinski program, they need to still generate code
-// that displays such a triangle. If yes, then one usually
-// can take comfort that all is well. If not, then something
-// went wrong during the optimisations.
-
-
-
-// (5) Write a function jtable that precomputes the "jump
-// table" for a bf-program. This function takes a bf-program
-// as an argument and Returns a Map[Int, Int]. The
-// purpose of this map is to record the information
-// that given on the position pc is a '[' or a ']',
-// then to which pc-position do we need to jump next?
-//
-// For example for the program
-//
-// "+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]"
-//
-// we obtain the map
-//
-// Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)
-//
-// This states that for the '[' on position 5, we need to
-// jump to position 20, which is just after the corresponding ']'.
-// Similarly, for the ']' on position 19, we need to jump to
-// position 6, which is just after the '[' on position 5, and so
-// on. The idea is to not calculate this information each time
-// we hit a bracket, but just look up this information in the
-// jtable. You can use the jumpLeft and jumpRight functions
-// from Part 1 for calculating the jtable.
-//
-// Then adapt the compute and run functions from Part 1 in order
-// to take advantage of the information stored in the jtable.
-// This means whenever jumpLeft and jumpRight was called previously,
-// you should look up the jump address in the jtable.
-
-
-def jtable(pg: String) : Map[Int, Int] =
- (0 until pg.length).collect { pc => pg(pc) match {
- case '[' => (pc -> jumpRight(pg, pc + 1, 0))
- case ']' => (pc -> jumpLeft(pg, pc - 1, 0))
- }}.toMap
-
-
-// testcase
-// jtable("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""")
-// => Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)
-
-
-def compute2(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
- if (0 <= pc && pc < pg.length) {
- val (new_pc, new_mp, new_mem) = pg(pc) match {
- case '>' => (pc + 1, mp + 1, mem)
- case '<' => (pc + 1, mp - 1, mem)
- case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
- case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
- case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
- case '[' =>
- if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
- case ']' =>
- if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
- case _ => (pc + 1, mp, mem)
- }
- compute2(pg, tb, new_pc, new_mp, new_mem)
- }
- else mem
-}
-
-
-def run2(pg: String, m: Mem = Map()) =
- compute2(pg, jtable(pg), 0, 0, m)
-
-//time_needed(1, run2(load_bff("benchmark.bf")))
-
-
-
-// (6) Write a function optimise which deletes "dead code" (everything
-// that is not a bf-command) and also replaces substrings of the form
-// [-] by a new command 0. The idea is that the loop [-] just resets the
-// memory at the current location to 0. In the compute3 and run3 functions
-// below you implement this command by writing the number 0 to mem(mp),
-// 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
-// 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 compute3(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
- if (0 <= pc && pc < pg.length) {
- val (new_pc, new_mp, new_mem) = pg(pc) match {
- case '0' => (pc + 1, mp, write(mem, mp, 0))
- case '>' => (pc + 1, mp + 1, mem)
- case '<' => (pc + 1, mp - 1, mem)
- case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
- case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
- case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
- case '[' =>
- if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
- case ']' =>
- if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
- case _ => (pc + 1, mp, mem)
- }
- compute3(pg, tb, new_pc, new_mp, new_mem)
- }
- else mem
-}
-
-def run3(pg: String, m: Mem = Map()) = {
- val pg_opt = optimise(pg)
- compute3(pg_opt, jtable(pg_opt), 0, 0, m)
-}
-
-
-// testcases
-
-//println(optimise(load_bff("collatz.bf")))
-//optimise(load_bff("benchmark.bf")) // should have inserted 0's
-//optimise(load_bff("mandelbrot.bf")).length // => 11203
-
-//time_needed(1, run3(load_bff("benchmark.bf")))
-
-
-
-// (7) Write a function combine which replaces sequences
-// of repated increment and decrement commands by appropriate
-// two-character commands. For example for sequences of +
-//
-// orig bf-cmds | replacement
-// ------------------------------
-// + | +A
-// ++ | +B
-// +++ | +C
-// |
-// ... |
-// |
-// +++....+++ | +Z
-// (where length = 26)
-//
-// Similar for the bf-command -, > and <. All other commands should
-// be unaffected by this change.
-//
-// Adapt the compute4 and run4 functions such that they can deal
-// appropriately with such two-character commands.
-
-def splice(cs: List[Char], acc: List[(Char, Int)]) : List[(Char, Int)] = (cs, acc) match {
- case (Nil, acc) => acc
- case ('[' :: cs, acc) => splice(cs, ('[', 1) :: acc)
- case (']' :: cs, acc) => splice(cs, (']', 1) :: acc)
- case ('.' :: cs, acc) => splice(cs, ('.', 1) :: acc)
- case ('0' :: cs, acc) => splice(cs, ('0', 1) :: acc)
- case (c :: cs, Nil) => splice(cs, List((c, 1)))
- case (c :: cs, (d, n) :: acc) =>
- if (c == d && n < 26) splice(cs, (c, n + 1) :: acc)
- else splice(cs, (c, 1) :: (d, n) :: acc)
-}
-
-def spl(s: String) = splice(s.toList, Nil).reverse
-
-//spl(load_bff("benchmark.bf"))
-
-def combine(s: String) : String = {
- (for ((c, n) <- spl(s)) yield c match {
- case '>' => List('>', (n + '@').toChar)
- case '<' => List('<', (n + '@').toChar)
- case '+' => List('+', (n + '@').toChar)
- case '-' => List('-', (n + '@').toChar)
- case _ => List(c)
- }).flatten.mkString
-}
-
-
-//combine(load_bff("benchmark.bf"))
-
-def compute4(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
- if (0 <= pc && pc < pg.length) {
- val (new_pc, new_mp, new_mem) = pg(pc) match {
- case '0' => (pc + 1, mp, write(mem, mp, 0))
- case '>' => (pc + 2, mp + (pg(pc + 1) - '@'), mem)
- case '<' => (pc + 2, mp - (pg(pc + 1) - '@'), mem)
- case '+' => (pc + 2, mp, write(mem, mp, sread(mem, mp) + (pg(pc + 1) - '@')))
- case '-' => (pc + 2, mp, write(mem, mp, sread(mem, mp) - (pg(pc + 1) - '@')))
- case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
- case '[' =>
- if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
- case ']' =>
- if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
- case _ => (pc + 1, mp, mem)
- }
- compute4(pg, tb, new_pc, new_mp, new_mem)
- }
- else mem
-}
-
-def run4(pg: String, m: Mem = Map()) = {
- val pg_opt = combine(optimise(pg))
- compute4(pg_opt, jtable(pg_opt), 0, 0, m)
-}
-
-// 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")))
-
-//time_needed(1, run(load_bff("sierpinski.bf")))
-//time_needed(1, run4(load_bff("sierpinski.bf")))
-
-//println(time_needed(1, run4(load_bff("mandelbrot.bf"))))
-
-
-}
-
-/*
-import CW10b._
-println(time_needed(1, run(load_bff("collatz.bf"))))
-println(time_needed(1, run2(load_bff("collatz.bf"))))
-println(time_needed(1, run3(load_bff("collatz.bf"))))
-println(time_needed(1, run4(load_bff("collatz.bf"))))
-*/
--- a/solutions5/collatz.bf Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-
->++++[<++++++++++>-]<+++++++++.[-]>+++++[<++++++++++>-]<++++++++.[-]>+++[<++++++++++>-]<++.[-]>++++[<++++++++++>-]<+++++++++.[-]>+++[<++++++++++>-]<++.[-]>++++++[<++++++++++>-]<+.[-]>++++++[<++++++++++>-]<++.[-]>+++[<++++++++++>-]<++.[-]>++++[<++++++++++>-]<++++++++.[-]++++++++++.[-]++>+[<[>>+>+<<<-]>>>[<<<+>>>-]<+>>+++[<++++++++++>-]<+>>+<<<[>>+<<-]>>[>-]>[<<<+>[-]>>->]<+<<[>-[>-]>[<<<+>[-]+>>->]<+<<-]>[-]>-<<<[<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]>>>>>>>>>>>>>>>>>>>+>+[<<<<<<<<<<<<<<<<<<<<<[>>>>>>>>>>>>>>>>>>>>>>+>+<<<<<<<<<<<<<<<<<<<<<<<-]>>>>>>>>>>>>>>>>>>>>>>>[<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>>-]>>+<<<[>>+<<-]>>[>-]>[<<<+>[-]>>->]<+<<[>-[>-]>[<<<+>[-]+>>->]<+<<-]>[-]>-<<<[>+<[-]]+>[<->-]<[<<<<<<<<<<<<<<<<<<<<<<[>>>>>>>>>>>>>>>>>>>>>>>>+>+<<<<<<<<<<<<<<<<<<<<<<<<<-]>>>>>>>>>>>>>>>>>>>>>>>>>[<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>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-]>>->]<+<<[>-[>-]>[<<<+>[-]+>>->]<+<<-]>[-]>-<<<[>+<[-]]+>[<->-]<[<<[>>>>+>+<<<<<-]>>>>>[<<<<<+>>>>>-]<[<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>-]<<<<<<<<<<<<<<<<<<<<<[[>>]+[<<]>>-]+[>>]<[<[<<]>+>>>>>>>>>>>>>>>>>>>>>+<<<<<<<<<<<<<<<<<<<<[>>]<-]<[<<]>[>[>>]<+<[<<]>-]>[>>]<<[-<<]>>>>>>>>>>>>>>>>>>>>>>>>++++[<++++++++++>-]<++++++++<[>>+>+<<<-]>>>[<<<+>>>-]<[<+>-]<.[-]<[-]<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]+[<->-]<<<<[-]>>>[<<<+>>>-]<[-]<+>]<-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]++++++++++.[-]<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]+[<+>-]<<<<[-]>>>[<<<+>>>-]<[-]<+>]<-]
\ No newline at end of file
--- a/solutions5/mandelbrot.bf Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-// a Mandelbrot set generator in brainf___ written by Erik Bosman
-// (http://esoteric.sange.fi/brainfuck/utils/mandelbrot/)
-
-
-+++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[
->>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+
-<<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>>
->+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>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 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
->++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
-[>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
-++++++++[>++++++++++[>++++++++++[>++++++++++[>+
-+++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++.
\ No newline at end of file
--- a/testing5/bf.scala Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,227 +0,0 @@
-// Core Part about an Interpreter for
-// the Brainf***++ language
-//==============================================
-
-object CW10a {
-
-
-// representation of Bf memory
-
-type Mem = Map[Int, Int]
-
-
-// (1) Write a function that takes a file name as argument and
-// and requests the corresponding file from disk. It Returns the
-// content of the file as a String. If the file does not exists,
-// the function should Return the empty string.
-
-import io.Source
-import scala.util._
-
-def load_bff(name: String) : String =
- Try(Source.fromFile(name)("ISO-8859-1").mkString).getOrElse("")
-
-
-// (2) Complete the functions for safely reading
-// and writing brainf***++ memory. Safely read should
-// Return the value stored in the Map for a given memory
-// pointer, provided it exists; otherwise it Returns 0. The
-// writing function generates a new Map with the
-// same data, except at the given memory pointer the
-// value v is stored.
-
-
-def sread(mem: Mem, mp: Int) : Int =
- mem.getOrElse(mp, 0)
-
-def write(mem: Mem, mp: Int, v: Int) : Mem =
- mem.updated(mp, v)
-
-
-// (3) Implement the two jumping instructions in the
-// brainf***++ language. In jumpRight, given a program and
-// a program counter move the program counter to the right
-// until after the *matching* ]-command. Similarly,
-// jumpLeft implements the move to the left to just after
-// the *matching* [-command.
-
-def jumpRight(prog: String, pc: Int, level: Int) : Int = {
- if (prog.length <= pc) pc
- else (prog(pc), level) match {
- case (']', 0) => pc + 1
- case (']', l) => jumpRight(prog, pc + 1, l - 1)
- case ('[', l) => jumpRight(prog, pc + 1, l + 1)
- case (_, l) => jumpRight(prog, pc + 1, l)
- }
-}
-
-def jumpLeft(prog: String, pc: Int, level: Int) : Int = {
- if (pc < 0) pc
- else (prog(pc), level) match {
- case ('[', 0) => pc + 1
- case ('[', l) => jumpLeft(prog, pc - 1, l - 1)
- case (']', l) => jumpLeft(prog, pc - 1, l + 1)
- case (_, l) => jumpLeft(prog, pc - 1, l)
- }
-}
-
-// test cases
-//jumpRight("""--[..+>--].>.++""", 3, 0) // => 10
-//jumpLeft("""--[..+>--].>.++""", 8, 0) // => 3
-//jumpRight("""--[..[+>]--].>.++""", 3, 0) // => 12
-//jumpRight("""--[..[[-]+>[.]]--].>.++""", 3, 0) // => 18
-//jumpRight("""--[..[[-]+>[.]]--.>.++""", 3, 0) // => 22 (outside)
-//jumpLeft("""[******]***""", 7, 0) // => -1 (outside)
-
-// (4) Complete the compute function that interprets (runs) a brainf***++
-// program: the arguments are a program (represented as a string), a program
-// counter, a memory counter and a brainf***++ memory. It Returns the
-// memory at the stage when the execution of the brainf***++ program
-// finishes. The interpretation finishes once the program counter
-// pc is pointing to something outside the program string.
-// If the pc points to a character inside the program, the pc,
-// memory pointer and memory need to be updated according to
-// rules of the brainf***++ language. Then, recursively, the compute
-// function continues with the command at the new program
-// counter.
-//
-// Implement the run function that calls compute with the program
-// counter and memory counter set to 0.
-
-def compute(prog: String, pc: Int, mp: Int, mem: Mem) : Mem = {
- if (0 <= pc && pc < prog.length) {
- val (new_pc, new_mp, new_mem) = prog(pc) match {
- case '>' => (pc + 1, mp + 1, mem)
- case '<' => (pc + 1, mp - 1, mem)
- case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
- case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
- case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
- //case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
- //case ',' => (pc + 1, mp, write(mem, mp, scala.io.StdIn.readByte()))
- case '[' =>
- if (sread(mem, mp) == 0) (jumpRight(prog, pc + 1, 0), mp, mem) else (pc + 1, mp, mem)
- case ']' =>
- if (sread(mem, mp) != 0) (jumpLeft(prog, pc - 1, 0), mp, mem) else (pc + 1, mp, mem)
-
- // new commands
- case '@' => (pc + 1, mp, write(mem, sread(mem, mp), sread(mem, mp - 1)))
- case '*' => (pc + 1, mp, write(mem, mp, sread(mem, mp) * sread(mem, mp -1)))
- case '#' => { println(s"${sread(mem, mp)}"); (pc + 1, mp, mem) }
-
- case _ => (pc + 1, mp, mem)
- }
- compute(prog, new_pc, new_mp, new_mem)
- }
- else mem
-}
-
-def run(prog: String, m: Mem = Map()) = compute(prog, 0, 0, m)
-
-
-
-
-
-// some sample bf/bf++-programs collected from the Internet
-//==========================================================
-
-
-// some contrived (small) programs
-//---------------------------------
-
-// clears the 0-cell
-//run("[-]", Map(0 -> 100)) // Map will be 0 -> 0
-
-// moves content of the 0-cell to 1-cell
-//run("[->+<]", Map(0 -> 10)) // Map will be 0 -> 0, 1 -> 10
-
-
-// copies content of the 0-cell to 2-cell and 4-cell
-//run("[>>+>>+<<<<-]", Map(0 -> 42)) // Map(0 -> 0, 2 -> 42, 4 -> 42)
-
-
-// prints out numbers 0 to 9
-//run("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""")
-
-// bf++ program calculating the cube-function, 10 * 10 * 10 = 1000
-//run("""++++++++++#>+***#""") // Map(0 -> 10, 1 -> 1000)
-
-
-// bf++ program copies 3 from 0-cell to to cells 1, 4, 5, 6 and 7
-// (note that because of how the program wprks cell 1 will contain 7)
-//run("""+++>+@+@+@+@+@""") // Map(0 -> 3, 1 -> 7, 4 -> 3, 5 -> 3, 6 -> 3, 7 -> 3)
-
-
-
-// some more "useful" programs
-//-----------------------------
-
-// hello world program 1
-//run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
-// ..+++.>>.<-.<.+++.------.--------.>>+.>++.""")
-
-// hello world program 2
-//run("""++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>+
-// +.<<+++++++++++++++.>.+++.------.--------.>+.>.""")
-
-// hello world program 3
-//run("""+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..
-// +++.>-.------------.<++++++++.--------.+++.------.--------.>+.""")
-
-
-// draws the Sierpinski triangle
-//run(load_bff("sierpinski.bf"))
-
-
-//fibonacci numbers below 100
-//run("""+++++++++++
-// >+>>>>++++++++++++++++++++++++++++++++++++++++++++
-// >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
-// +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
-// <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
-// -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
-// >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
-// +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
-// ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
-// <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
-// [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]""")
-
-//outputs the square numbers up to 10000
-//run("""++++[>+++++<-]>[<+++++>-]+<+[>[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+
-// >>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]
-// <<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]""")
-
-
-// calculates 2 to the power of 6
-//(example from a C-to-BF compiler at https://github.com/elikaski/BF-it)
-//run(""">>[-]>[-]++>[-]++++++><<<>>>>[-]+><>[-]<<[-]>[>+<<+>-]>[<+>-]
-// <><[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-]
-// <[>+>+<<-]>[<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<[[-]>[-]<<[>+>
-// +<<-]>>[<<+>>-][-]>[-]<<<<<[>>>>+>+<<<<<-]>>>>>[<<<<<+>>>>>-]
-// <<>>[-]>[-]<<<[>>>+<<<-]>>>[<<[<+>>+<-]>[<+>-]>-]<<<>[-]<<[-]
-// >[>+<<+>-]>[<+>-]<><[-]>[-]<<<[>>+>+<<<-]>>>-[<<<+>>>-]<[-]>[-]
-// <<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-]<[>+>+<<-]>
-// [<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<][-]>[-]<<[>+>+<<-]>>[<<+>
-// >-]<<<<<[-]>>>>[<<<<+>>>>-]<<<<><>[-]<<[-]>[>+<<+>-]>[<+>-]<>
-// <[-]>[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-]<<>>[-]>[-]>[-]>[-]>[-]>
-// [-]>[-]>[-]>[-]>[-]<<<<<<<<<<>>++++++++++<<[->+>-[>+>>]>[+[-<+
-// >]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<
-// ]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++
-// ++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<<><<<""")
-
-
-
-// a Mandelbrot set generator in brainf*** written by Erik Bosman
-// (http://esoteric.sange.fi/brainfuck/utils/mandelbrot/)
-//
-//run(load_bff("mandelbrot.bf"))
-
-
-// a benchmark program (counts down from 'Z' to 'A')
-//
-//run(load_bff("benchmark.bf"))
-
-// calculates the Collatz series for numbers from 1 to 30
-//
-//run(load_bff("collatz.bf"))
-
-}
--- a/testing5/bf_test.sh Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,137 +0,0 @@
-#!/bin/bash
-set -euo pipefail
-
-out=${1:-output}
-
-echo -e "" > $out
-
-echo -e "Below is the feedback for your submission of CW 10." >> $out
-echo -e "" >> $out
-
-
-# compilation tests
-
-function scala_compile {
- (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)
-}
-
-# functional tests
-
-function scala_assert {
- (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
-}
-
-# purity test
-
-function scala_vars {
- (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
-}
-
-
-# var, return, ListBuffer test
-#
-echo -e "bf.scala does not contain vars, returns etc?" >> $out
-
-if (scala_vars bf.scala)
-then
- echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out
- tsts0=$(( 0 ))
-else
- echo -e " --> success" >> $out
- tsts0=$(( 0 ))
-fi
-
-
-# compilation test
-if [ $tsts0 -eq 0 ]
-then
- echo -e "bf.scala runs?" >> $out
-
- if (scala_compile bf.scala)
- then
- echo -e " --> success" >> $out
- tsts1=$(( 0 ))
- else
- echo -e " --> SCALA DID NOT RUN BF.SCALA\n" >> $out
- tsts1=$(( 1 ))
- fi
-else
- tsts1=$(( 1 ))
-fi
-
-
-### bf tests
-
-if [ $tsts1 -eq 0 ]
-then
- echo -e " load_bff(\"benchmark.bf\").length == 188" >> $out
- echo -e " load_bff(\"foobar.bf\") == \"\"" >> $out
-
- if (scala_assert "bf.scala" "bf_test1.scala")
- then
- echo -e " --> success" >> $out
- else
- echo -e " --> \n ONE TEST FAILED\n" >> $out
- fi
-fi
-
-if [ $tsts1 -eq 0 ]
-then
- echo -e " sread(Map(), 2) == 0" >> $out
- echo -e " sread(Map(2 -> 1), 2) == 1" >> $out
- echo -e " write(Map(), 1, 2) == Map(1 -> 2)" >> $out
- echo -e " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" >> $out
-
- if (scala_assert "bf.scala" "bf_test2.scala")
- then
- echo -e " --> success" >> $out
- else
- echo -e " --> \n ONE TEST FAILED\n" >> $out
- fi
-fi
-
-
-
-if [ $tsts1 -eq 0 ]
-then
- echo -e " jumpRight(\"[xxxxxx]xxx\", 1, 0) == 8" >> $out
- echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" >> $out
- echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" >> $out
- echo -e " jumpRight(\"[xx[xxx]xxx\", 1, 0) == 11" >> $out
- echo -e " jumpRight(\"[x[][]x]xxx\", 1, 0) == 8" >> $out
- echo -e " jumpLeft(\"[xxxxxx]xxx\", 6, 0) == 1" >> $out
- echo -e " jumpLeft(\"[xxxxxx]xxx\", 7, 0) == -1" >> $out
- echo -e " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" >> $out
-
- if (scala_assert "bf.scala" "bf_test3.scala")
- then
- echo -e " --> success" >> $out
- else
- echo -e " --> \n ONE TEST FAILED\n" >> $out
- fi
-fi
-
-
-
-if [ $tsts1 -eq 0 ]
-then
- echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" >> $out
- echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" >> $out
- echo -e " run(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" >> $out
- echo -e " run(\"++++++++++#>+***#\") == Map(0 -> 10, 1 -> 1000))" >> $out
- echo -e " run(\"+++>+@+@+@+@+@\") == Map(0 -> 3, 1 -> 7, 4 -> 3, 5 -> 3, 6 -> 3, 7 -> 3)" >> $out
-
- echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" >> $out
- echo -e " <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" >> $out
-
- if (scala_assert "bf.scala" "bf_test4.scala")
- then
- echo -e " --> success" >> $out
- else
- echo -e " --> \n ONE TEST FAILED\n" >> $out
- fi
-fi
-
-
-
-
--- a/testing5/bf_test1.scala Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-import CW10a._
-
-assert(load_bff("benchmark.bf").length == 188)
-assert(load_bff("foobar.bf") == "")
--- a/testing5/bf_test2.scala Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-import CW10a._
-
-assert(sread(Map(), 2) == 0)
-assert(sread(Map(2 -> 1), 2) == 1)
-assert(write(Map(), 1, 2) == Map(1 -> 2))
-assert(write(Map(1 -> 0), 1, 2) == Map(1 -> 2))
--- a/testing5/bf_test3.scala Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-import CW10a._
-
-assert(jumpRight("[xxxxxx]xxx", 1, 0) == 8)
-assert(jumpRight("[xx[x]x]xxx", 1, 0) == 8)
-assert(jumpRight("[xx[x]x]xxx", 1, 0) == 8)
-assert(jumpRight("[xx[xxx]xxx", 1, 0) == 11)
-assert(jumpRight("[x[][]x]xxx", 1, 0) == 8)
-assert(jumpLeft("[xxxxxx]xxx", 6, 0) == 1)
-assert(jumpLeft("[xxxxxx]xxx", 7, 0) == -1)
-assert(jumpLeft("[x[][]x]xxx", 6, 0) == 1)
--- a/testing5/bf_test4.scala Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-import CW10a._
-
-assert(run("[-]", Map(0 -> 100)) == Map(0 -> 0))
-assert(run("[->+<]", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10))
-assert(run("[>>+>>+<<<<-]", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42))
-assert(run("++++++++++#>+***#") == Map(0 -> 10, 1 -> 1000))
-assert(run("+++>+@+@+@+@+@") == Map(0 -> 3, 1 -> 7, 4 -> 3, 5 -> 3, 6 -> 3, 7 -> 3))
-
-
-
-val hw_urban = """+++++[->++++++++++<]>--<+++[->>++++++++++
- <<]>>++<<----------[+>.>.<+<]"""
-assert(run(hw_urban) == Map(0 -> 0, 1 -> 58, 2 -> 32))
-
--- a/testing5/bf_test5.scala Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-import CW10b._
-
-assert(jtable("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""") ==
- Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6))
-
--- a/testing5/bf_test6.scala Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-import CW10b._
-
-assert(optimise(load_bff("benchmark.bf")).length == 181)
-assert(optimise(load_bff("mandelbrot.bf")).length == 11203)
--- a/testing5/bf_test7.scala Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-import CW10b._
-
-assert(combine(optimise(load_bff("benchmark.bf"))).length == 134)
-assert(combine(optimise(load_bff("mandelbrot.bf"))).length == 6509)
--- a/testing5/bfc.scala Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,312 +0,0 @@
-// Part 2 about a "Compiler" for the Brainf*** language
-//======================================================
-
-object CW10b {
-
-// !!! Copy any function you need from file bf.scala !!!
-//
-// If you need any auxiliary function, feel free to
-// implement it, but do not make any changes to the
-// templates below.
-
-
-def time_needed[T](n: Int, code: => T) = {
- val start = System.nanoTime()
- for (i <- 0 until n) code
- val end = System.nanoTime()
- (end - start)/(n * 1.0e9)
-}
-
-type Mem = Map[Int, Int]
-
-
-import io.Source
-import scala.util._
-
-def load_bff(name: String) : String =
- Try(Source.fromFile(name)("ISO-8859-1").mkString).getOrElse("")
-
-def sread(mem: Mem, mp: Int) : Int =
- mem.getOrElse(mp, 0)
-
-def write(mem: Mem, mp: Int, v: Int) : Mem =
- mem.updated(mp, v)
-
-def jumpRight(prog: String, pc: Int, level: Int) : Int = {
- if (prog.length <= pc) pc
- else (prog(pc), level) match {
- case (']', 0) => pc + 1
- case (']', l) => jumpRight(prog, pc + 1, l - 1)
- case ('[', l) => jumpRight(prog, pc + 1, l + 1)
- case (_, l) => jumpRight(prog, pc + 1, l)
- }
-}
-
-def jumpLeft(prog: String, pc: Int, level: Int) : Int = {
- if (pc < 0) pc
- else (prog(pc), level) match {
- case ('[', 0) => pc + 1
- case ('[', l) => jumpLeft(prog, pc - 1, l - 1)
- case (']', l) => jumpLeft(prog, pc - 1, l + 1)
- case (_, l) => jumpLeft(prog, pc - 1, l)
- }
-}
-
-def compute(prog: String, pc: Int, mp: Int, mem: Mem) : Mem = {
- if (0 <= pc && pc < prog.length) {
- val (new_pc, new_mp, new_mem) = prog(pc) match {
- case '>' => (pc + 1, mp + 1, mem)
- case '<' => (pc + 1, mp - 1, mem)
- case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
- case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
- case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
- case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
- case '[' =>
- if (sread(mem, mp) == 0) (jumpRight(prog, pc + 1, 0), mp, mem) else (pc + 1, mp, mem)
- case ']' =>
- if (sread(mem, mp) != 0) (jumpLeft(prog, pc - 1, 0), mp, mem) else (pc + 1, mp, mem)
- case _ => (pc + 1, mp, mem)
- }
- compute(prog, new_pc, new_mp, new_mem)
- }
- else mem
-}
-
-def run(prog: String, m: Mem = Map()) = compute(prog, 0, 0, m)
-
-
-// The baseline to what we can compare our "compiler"
-// implemented below. It should require something like
-// 60 seconds for the calculation on my laptop
-//
-//time_needed(1, run(load_bff("benchmark.bf")))
-
-
-
-// DEBUGGING INFORMATION!!!
-//
-// Compiler, even real ones, are fiedishly difficult to get
-// to prduce correct code. The point is that for example for
-// the sierpinski program, they need to still generate code
-// that displays such a triangle. If yes, then one usually
-// can take comfort that all is well. If not, then something
-// went wrong during the optimisations.
-
-
-
-// (5) Write a function jtable that precomputes the "jump
-// table" for a bf-program. This function takes a bf-program
-// as an argument and Returns a Map[Int, Int]. The
-// purpose of this map is to record the information
-// that given on the position pc is a '[' or a ']',
-// then to which pc-position do we need to jump next?
-//
-// For example for the program
-//
-// "+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]"
-//
-// we obtain the map
-//
-// Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)
-//
-// This states that for the '[' on position 5, we need to
-// jump to position 20, which is just after the corresponding ']'.
-// Similarly, for the ']' on position 19, we need to jump to
-// position 6, which is just after the '[' on position 5, and so
-// on. The idea is to not calculate this information each time
-// we hit a bracket, but just look up this information in the
-// jtable. You can use the jumpLeft and jumpRight functions
-// from Part 1 for calculating the jtable.
-//
-// Then adapt the compute and run functions from Part 1 in order
-// to take advantage of the information stored in the jtable.
-// This means whenever jumpLeft and jumpRight was called previously,
-// you should look up the jump address in the jtable.
-
-
-def jtable(pg: String) : Map[Int, Int] =
- (0 until pg.length).collect { pc => pg(pc) match {
- case '[' => (pc -> jumpRight(pg, pc + 1, 0))
- case ']' => (pc -> jumpLeft(pg, pc - 1, 0))
- }}.toMap
-
-
-// testcase
-// jtable("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""")
-// => Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)
-
-
-def compute2(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
- if (0 <= pc && pc < pg.length) {
- val (new_pc, new_mp, new_mem) = pg(pc) match {
- case '>' => (pc + 1, mp + 1, mem)
- case '<' => (pc + 1, mp - 1, mem)
- case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
- case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
- case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
- case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
- case '[' =>
- if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
- case ']' =>
- if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
- case _ => (pc + 1, mp, mem)
- }
- compute2(pg, tb, new_pc, new_mp, new_mem)
- }
- else mem
-}
-
-
-def run2(pg: String, m: Mem = Map()) =
- compute2(pg, jtable(pg), 0, 0, m)
-
-//time_needed(1, run2(load_bff("benchmark.bf")))
-
-
-
-// (6) Write a function optimise which deletes "dead code" (everything
-// that is not a bf-command) and also replaces substrings of the form
-// [-] by a new command 0. The idea is that the loop [-] just resets the
-// memory at the current location to 0. In the compute3 and run3 functions
-// below you implement this command by writing the number 0 to mem(mp),
-// 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
-// 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 compute3(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
- if (0 <= pc && pc < pg.length) {
- val (new_pc, new_mp, new_mem) = pg(pc) match {
- case '0' => (pc + 1, mp, write(mem, mp, 0))
- case '>' => (pc + 1, mp + 1, mem)
- case '<' => (pc + 1, mp - 1, mem)
- case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
- case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
- case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
- case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
- case '[' =>
- if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
- case ']' =>
- if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
- case _ => (pc + 1, mp, mem)
- }
- compute3(pg, tb, new_pc, new_mp, new_mem)
- }
- else mem
-}
-
-def run3(pg: String, m: Mem = Map()) = {
- val pg_opt = optimise(pg)
- compute3(pg_opt, jtable(pg_opt), 0, 0, m)
-}
-
-
-// testcases
-
-//optimise(load_bff("benchmark.bf")) // should have inserted 0's
-//optimise(load_bff("benchmark.bf")).length // => 181
-//optimise(load_bff("mandelbrot.bf")).length // => 11203
-
-//time_needed(1, run3(load_bff("benchmark.bf")))
-
-
-
-// (7) Write a function combine which replaces sequences
-// of repated increment and decrement commands by appropriate
-// two-character commands. For example for sequences of +
-//
-// orig bf-cmds | replacement
-// ------------------------------
-// + | +A
-// ++ | +B
-// +++ | +C
-// |
-// ... |
-// |
-// +++....+++ | +Z
-// (where length = 26)
-//
-// Similar for the bf-command -, > and <. All other commands should
-// be unaffected by this change.
-//
-// Adapt the compute4 and run4 functions such that they can deal
-// appropriately with such two-character commands.
-
-def splice(cs: List[Char], acc: List[(Char, Int)]) : List[(Char, Int)] = (cs, acc) match {
- case (Nil, acc) => acc
- case ('[' :: cs, acc) => splice(cs, ('[', 1) :: acc)
- case (']' :: cs, acc) => splice(cs, (']', 1) :: acc)
- case ('.' :: cs, acc) => splice(cs, ('.', 1) :: acc)
- case (',' :: cs, acc) => splice(cs, (',', 1) :: acc)
- case ('0' :: cs, acc) => splice(cs, ('0', 1) :: acc)
- case (c :: cs, Nil) => splice(cs, List((c, 1)))
- case (c :: cs, (d, n) :: acc) =>
- if (c == d && n < 26) splice(cs, (c, n + 1) :: acc)
- else splice(cs, (c, 1) :: (d, n) :: acc)
-}
-
-def spl(s: String) = splice(s.toList, Nil).reverse
-
-//spl(load_bff("benchmark.bf"))
-
-def combine(s: String) : String = {
- (for ((c, n) <- spl(s)) yield c match {
- case '>' => List('>', (n + '@').toChar)
- case '<' => List('<', (n + '@').toChar)
- case '+' => List('+', (n + '@').toChar)
- case '-' => List('-', (n + '@').toChar)
- case _ => List(c)
- }).flatten.mkString
-}
-
-
-//combine(load_bff("benchmark.bf"))
-
-def compute4(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
- if (0 <= pc && pc < pg.length) {
- val (new_pc, new_mp, new_mem) = pg(pc) match {
- case '0' => (pc + 1, mp, write(mem, mp, 0))
- case '>' => (pc + 2, mp + (pg(pc + 1) - '@'), mem)
- case '<' => (pc + 2, mp - (pg(pc + 1) - '@'), mem)
- case '+' => (pc + 2, mp, write(mem, mp, sread(mem, mp) + (pg(pc + 1) - '@')))
- case '-' => (pc + 2, mp, write(mem, mp, sread(mem, mp) - (pg(pc + 1) - '@')))
- case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
- case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
- case '[' =>
- if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
- case ']' =>
- if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem)
- case _ => (pc + 1, mp, mem)
- }
- compute4(pg, tb, new_pc, new_mp, new_mem)
- }
- else mem
-}
-
-def run4(pg: String, m: Mem = Map()) = {
- val pg_opt = combine(optimise(pg))
- compute4(pg_opt, jtable(pg_opt), 0, 0, m)
-}
-
-// testcases
-//combine(optimise(load_bff("benchmark.bf"))) // => """>A+B[<A+M>A-A]<A[[....."""
-//combine(optimise(load_bff("benchmark.bf"))).length // => 134
-//combine(optimise(load_bff("mandelbrot.bf"))).length // => 6509
-
-//time_needed(1, run4(load_bff("benchmark.bf")))
-
-//time_needed(1, run(load_bff("sierpinski.bf")))
-//time_needed(1, run4(load_bff("sierpinski.bf")))
-
-//time_needed(1, run4(load_bff("mandelbrot.bf")))
-
-
-}
--- a/testing5/bfc_test.sh Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-#!/bin/bash
-set -e
-
-out=${1:-output}
-
-echo -e "" > $out
-
-echo -e "Below is the feedback for your submission of CW 10, Part 2." >> $out
-echo -e "" >> $out
-
-
-# compilation tests
-
-function scala_compile {
- (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)
-}
-
-# functional tests
-
-function scala_assert {
- (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" 2> /dev/null 1> /dev/null)
-}
-
-# purity test
-
-function scala_vars {
- (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
-}
-
-
-# var, return, ListBuffer test
-#
-echo -e "bfc.scala does not contain vars, returns etc?" >> $out
-
-if (scala_vars bfc.scala)
-then
- echo -e " --> FAIL (make triple-sure your program conforms to the required format)" >> $out
- tsts0=$(( 0 ))
-else
- echo -e " --> success" >> $out
- tsts0=$(( 0 ))
-fi
-
-
-# compilation test
-if [ $tsts0 -eq 0 ]
-then
- echo -e "bfc.scala runs?" >> $out
-
- if (scala_compile bfc.scala)
- then
- echo -e " --> success" >> $out
- tsts1=$(( 0 ))
- else
- echo -e " --> --> SCALA DID NOT RUN BFC.SCALA\n" >> $out
- tsts1=$(( 1 ))
- fi
-else
- tsts1=$(( 1 ))
-fi
-
-
-### bfc tests
-
-if [ $tsts1 -eq 0 ]
-then
- echo -e " jtable(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\") ==" >> $out
- echo -e " Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" >> $out
-
- if (scala_assert "bfc.scala" "bf_test5.scala")
- then
- echo -e " --> success" >> $out
- else
- echo -e " --> \n ONE TEST FAILED\n" >> $out
- fi
-fi
-
-
-
-if [ $tsts1 -eq 0 ]
-then
- echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out
- echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11203" >> $out
-
- if (scala_assert "bfc.scala" "bf_test6.scala")
- then
- echo -e " --> success" >> $out
- else
- echo -e " --> \n ONE TEST FAILED\n" >> $out
- fi
-fi
-
-
-
-if [ $tsts1 -eq 0 ]
-then
- echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" >> $out
- echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6509" >> $out
-
- if (scala_assert "bfc.scala" "bf_test7.scala")
- then
- echo -e " --> success" >> $out
- else
- echo -e " --> \n ONE TEST FAILED\n" >> $out
- fi
-fi
-
-
-
--- a/testing5/mandelbrot.bf Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-// a Mandelbrot set generator in brainf___ written by Erik Bosman
-// (http://esoteric.sange.fi/brainfuck/utils/mandelbrot/)
-
-
-+++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[
->>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+
-<<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>>
->+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>>
->>>>>[-]+<<<<<<++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<+++++++[-[->>>
->>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[[-]>>>>>>[>>>>>
->>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<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<<<<]<+<<<<<<<<<]>+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>
-+>>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[-<<<<<<->>>>>>]+<
-<<<<<[->>>>>>->>[-<<<<<<<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+<<<<<<<<<<<<<<<<<[<<<<<<<
-<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>
--<<[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>
->>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++
-+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<<
-<<<<<]]>>>]
--- a/testing5/mark Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-#!/bin/bash
-###set -e
-
-trap "exit" INT
-
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-
-cp $DIR/* .
-
-./bf_test.sh tmp_output1
-
-echo -e "Here is an automated test report for some work in the Part10 directory. Please note that this is not the mark for your work; it is provided only in the hope that it is useful in developing your solution. Please ensure you test your code on your own machine in order to make sure it is bug free!! Passing these tests does not guarantee your code is free from bugs!! Also after the deadline, your code will be marked against a different, more thorough set of test cases.\n\n" > $1
-
-
-cat tmp_output1 >> $1
-
--- a/testing5/mark2 Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-#!/bin/bash
-###set -e
-
-trap "exit" INT
-
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-
-cp $DIR/* .
-
-./bfc_test.sh tmp_output2
-
-echo -e "Here is an automated test report for your work in the Part10 directory. Please note that this is not the mark for your work; it is provided only in the hope that it is useful in developing your solution. Please ensure you test your code on your own machine in order to make sure it is bug free!! Passing these tests does not guarantee your code is free from bugs!! Also after the deadline, your code will be marked against a different, more thorough set of test cases.\n\n" > $1
-
-
-cat tmp_output2 >> $1
-
--- a/testing5/sierpinski.bf Mon Nov 02 02:31:44 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[
-->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
-]>.>+[>>]>+]