main_testing5/bfc.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 15 Jan 2021 02:40:57 +0000
changeset 384 6e1237691307
parent 348 b5b6ed38c2f2
child 404 bf20a9fa5c29
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
     1
// Core Part about a "Compiler" for the Brainf*** language
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
//======================================================
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
     4
286
5c57c407e27b updated
Christian Urban <urbanc@in.tum.de>
parents: 250
diff changeset
     5
object CW10b {
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
     7
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
// !!! Copy any function you need from file bf.scala !!!
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
//
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
// If you need any auxiliary function, feel free to 
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
// implement it, but do not make any changes to the
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
// templates below.
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    14
type Mem = Map[Int, Int]
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    16
import io.Source
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    17
import scala.util._
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    18
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    19
def load_bff(name: String) : String = 
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    20
  Try(scala.io.Source.fromFile(name)("ISO-8859-1").mkString).getOrElse("")
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    21
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    22
def sread(mem: Mem, mp: Int) : Int = mem.getOrElse(mp, 0)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    23
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    24
def write(mem: Mem, mp: Int, v: Int) : Mem = mem + (mp -> v)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    25
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    26
def jumpRight(prog: String, pc: Int, level: Int) : Int = {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    27
    pc match {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    28
        case pc: Int if (pc >= 0 && pc < prog.length) => {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    29
            prog(pc) match {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    30
                case '[' => jumpRight(prog, pc + 1, level + 1)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    31
                case ']' => if (level == 0) pc + 1 else jumpRight(prog, pc + 1, level - 1)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    32
                case _ => jumpRight(prog, pc + 1, level)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    33
            }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    34
        }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    35
        case _ => pc
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    36
    }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    37
}
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    38
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    39
def jumpLeft(prog: String, pc: Int, level: Int) : Int = {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    40
    pc match {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    41
        case pc: Int if (pc >= 0 && pc < prog.length) => {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    42
            prog(pc) match {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    43
                case '[' => if (level == 0) pc + 1 else jumpLeft(prog, pc - 1, level - 1)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    44
                case ']' => jumpLeft(prog, pc - 1, level + 1)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    45
                case _ => jumpLeft(prog, pc - 1, level)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    46
            }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    47
        }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    48
        case _ => pc
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    49
    }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    50
}
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    51
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    52
def get_position(prog: String, pc: Int, level: Int) : Int = {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    53
  prog(pc) match {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    54
    case '[' => jumpRight(prog, pc + 1, level)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    55
    case ']' => jumpLeft(prog, pc - 1, level)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    56
    case _ => println("Something went horrible wrong, I am sorry"); 0
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    57
  }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    58
}
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    59
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    60
// DEBUGGING INFORMATION FOR COMPILERS!!!
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    61
//
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    62
// Compiler, even real ones, are fiendishly difficult to get
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    63
// to produce correct code. One way to debug them is to run
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    64
// example programs ``unoptimised''; and then optimised. Does
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    65
// the optimised version still produce the same result?
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    66
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    67
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    68
// for timing purposes
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
def time_needed[T](n: Int, code: => T) = {
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  val start = System.nanoTime()
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  for (i <- 0 until n) code
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  val end = System.nanoTime()
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  (end - start)/(n * 1.0e9)
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    78
// TASKS
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    79
//=======
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
// (5) Write a function jtable that precomputes the "jump
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
//     table" for a bf-program. This function takes a bf-program 
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
//     as an argument and Returns a Map[Int, Int]. The 
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    84
//     purpose of this map is to record the information about
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    85
//     pc positions where '[' or a ']' are stored. The information
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    86
//     is to which pc-position do we need to jump next?
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
// 
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
//     For example for the program
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
//    
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
//       "+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]"
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
//
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
//     we obtain the map
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
//
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
//       Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
//  
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
//     This states that for the '[' on position 5, we need to
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
//     jump to position 20, which is just after the corresponding ']'.
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
//     Similarly, for the ']' on position 19, we need to jump to
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
//     position 6, which is just after the '[' on position 5, and so
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
//     on. The idea is to not calculate this information each time
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
//     we hit a bracket, but just look up this information in the 
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
//     jtable. You can use the jumpLeft and jumpRight functions
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
//     from Part 1 for calculating the jtable.
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
//
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   105
//     Then adapt the compute and run functions from Part 1 
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   106
//     in order to take advantage of the information stored in the jtable. 
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
//     This means whenever jumpLeft and jumpRight was called previously,
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   108
//     you should immediately look up the jump address in the jtable.
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   109
//  for ((char, index) <- str.zipWithIndex if (List('[', ']').contains(char))) yield (index, get_position(str, index, 0))
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
 
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   112
def jtable(pg: String) : Map[Int, Int] = {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   113
  val table = for ((char, index) <- pg.zipWithIndex if (List('[', ']').contains(char))) yield (index, get_position(pg, index, 0))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   114
  table.toMap
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   115
}
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
// testcase
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   119
//
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
// jtable("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""")
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
// =>  Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
def compute2(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   125
  pc match {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   126
    case pc: Int if (pc >= 0 && pc < pg.length) => {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   127
      pg(pc) match {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   128
        case '>' => compute2(pg, tb, pc + 1, mp + 1, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   129
        case '<' => compute2(pg, tb, pc + 1, mp - 1, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   130
        case '+' => compute2(pg, tb, pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   131
        case '-' => compute2(pg, tb, pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   132
        case '.' => print(sread(mem, mp).toChar); compute2(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   133
        case '[' => if (sread(mem, mp) == 0) compute2(pg, tb, tb(pc), mp, mem) else compute2(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   134
        case ']' => if (sread(mem, mp) != 0) compute2(pg, tb, tb(pc), mp, mem) else compute2(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   135
        case '*' => compute2(pg, tb, pc + 1, mp, write(mem, mp, sread(mem, mp) * sread(mem, mp - 1)))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   136
        case '@' => compute2(pg, tb, pc + 1, mp, write(mem, mem(mp), sread(mem, mp - 1)))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   137
        case '#' => print(sread(mem, mp)); compute2(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   138
        case _ => compute2(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   139
      }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   140
    }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   141
    case _ => mem
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  }
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   143
}
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   144
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   145
def run2(pg: String, m: Mem = Map()) = {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   146
  compute2(pg, jtable(pg), 0, 0, m)
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   150
// testcases
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   151
// time_needed(1, run2(load_bff("./main5/benchmark.bf")))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   152
// time_needed(1, run2(load_bff("./main5/sierpinski.bf")))
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
// (6) Write a function optimise which deletes "dead code" (everything
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
// that is not a bf-command) and also replaces substrings of the form
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
// [-] by a new command 0. The idea is that the loop [-] just resets the
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
// memory at the current location to 0. In the compute3 and run3 functions
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
// below you implement this command by writing the number 0 to mem(mp), 
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
// that is write(mem, mp, 0). 
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
//
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
// The easiest way to modify a string in this way is to use the regular
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
// expression """[^<>+-.,\[\]]""", which recognises everything that is 
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
// not a bf-command and replace it by the empty string. Similarly the
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   166
// regular expression """\[-\]""" finds all occurrences of [-] and 
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   167
// by using the Scala method .replaceAll you can replace it with the 
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
// string "0" standing for the new bf-command.
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   169
// load_bff("./main5/mandelbrot.bf").replaceAll("""[^<>+‐.\[\]@#*]""", "").replaceAll("""\[-\]""", "0")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   171
// "Correct" regex
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   172
// s.replaceAll("""[^<>+‐.\[\]@#*]""", "").replaceAll("""\[-\]""", "0")
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   173
// s.replaceAll("""[^<>+-.,\[\]]""", "").replaceAll("""\[-\]""", "0")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   175
def optimise(s: String) : String = {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   176
  //s.replaceAll("""[^<>+-.\[\]@#*]""","")
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   177
  // .replaceAll("""\[-\]""", "0")
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   178
  s.replaceAll("""[^<>+-.\[\]]""", "").replaceAll("""\[-\]""", "0")
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   179
}
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
def compute3(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   182
  pc match {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   183
    case pc: Int if (pc >= 0 && pc < pg.length) => {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   184
      pg(pc) match {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   185
        case '>' => compute3(pg, tb, pc + 1, mp + 1, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   186
        case '<' => compute3(pg, tb, pc + 1, mp - 1, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   187
        case '+' => compute3(pg, tb, pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   188
        case '-' => compute3(pg, tb, pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   189
        case '.' => print(sread(mem, mp).toChar); compute3(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   190
        case '[' => if (sread(mem, mp) == 0) compute3(pg, tb, tb(pc), mp, mem) else compute3(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   191
        case ']' => if (sread(mem, mp) != 0) compute3(pg, tb, tb(pc), mp, mem) else compute3(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   192
        case '*' => compute3(pg, tb, pc + 1, mp, write(mem, mp, sread(mem, mp) * sread(mem, mp - 1)))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   193
        case '@' => compute3(pg, tb, pc + 1, mp, write(mem, mem(mp), sread(mem, mp - 1)))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   194
        case '#' => print(sread(mem, mp)); compute3(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   195
        case '0' => compute3(pg, tb, pc + 1, mp, write(mem, mp, 0))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   196
        case _ => compute3(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   197
      }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   198
    }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   199
    case _ => mem
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
  }
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   203
def run3(pg: String, m: Mem = Map()) = {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   204
  val optimised = optimise(pg)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   205
  compute3(optimised, jtable(optimised), 0, 0, m)
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
// testcases
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   210
//
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   211
// optimise(load_bff("./main5/benchmark.bf"))          // should have inserted 0's
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   212
// optimise(load_bff("./main5/mandelbrot.bf")).length  // => 11205
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   213
// 
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   214
// time_needed(1, run3(load_bff("./main5/benchmark.bf")))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   215
// time_needed(1, run3(load_bff("./main5/mandelbrot.bf")))
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
// (7)  Write a function combine which replaces sequences
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   220
// of repeated increment and decrement commands by appropriate
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
// two-character commands. For example for sequences of +
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
//
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
//              orig bf-cmds  | replacement
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
//            ------------------------------
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
//              +             | +A 
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
//              ++            | +B
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
//              +++           | +C
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
//                            |
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
//              ...           |
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
//                            | 
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
//              +++....+++    | +Z
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
//                (where length = 26)
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
//
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
//  Similar for the bf-command -, > and <. All other commands should
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
//  be unaffected by this change.
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
//
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
//  Adapt the compute4 and run4 functions such that they can deal
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
//  appropriately with such two-character commands.
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   240
// val alphabet = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   241
val alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   242
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   243
// Try any alphabet, it will work as long as the character is recognised and the characters are unique
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   244
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   245
def get_number_from_character(char: Char) : Int = {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   246
  alphabet.indexOf(char) + 1
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   247
}
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   248
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   249
def get_character_from_number(int: Int) : Char = {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   250
  alphabet(int - 1)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   251
}
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   252
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   253
@annotation.tailrec 
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   254
def split_by_repetition(string : String, list : List[String] = Nil) : List[String] = {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   255
    if(string.size == 0) list.reverse 
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   256
    else {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   257
        val (left_substring, right_substring) = string.span(_ == string(0))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   258
        split_by_repetition(right_substring, left_substring :: list)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   259
    }
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   262
def combine(s: String) : String = {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   263
  val split_strings = split_by_repetition(s)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   264
  val lists = for (string <- split_strings) yield {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   265
    if (List("+"(0), "-"(0), "<"(0), ">"(0)).contains(string.head)) {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   266
      val long_repeat = s"${string.head}${alphabet.last}" * (string.size / alphabet.length)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   267
      val short_repeat = if ((string.size % alphabet.length) != 0) s"${string.head}${get_character_from_number(string.size % alphabet.length)}" else ""
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   268
      long_repeat + short_repeat
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   269
    } else string
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   270
  }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   271
  lists.mkString("")
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   272
}
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   274
// testcase
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   275
// combine(load_bff("./main5/benchmark.bf"))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   276
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   278
def compute4(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   279
  pc match {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   280
    case pc: Int if (pc >= 0 && pc < pg.length) => {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   281
      pg(pc) match {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   282
        case '>' => val number = get_number_from_character(pg(pc + 1)); compute4(pg, tb, pc + 2, mp + number, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   283
        case '<' => val number = get_number_from_character(pg(pc + 1)); compute4(pg, tb, pc + 2, mp - number, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   284
        case '+' => val number = get_number_from_character(pg(pc + 1)); compute4(pg, tb, pc + 2, mp, write(mem, mp, sread(mem, mp) + number))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   285
        case '-' => val number = get_number_from_character(pg(pc + 1)); compute4(pg, tb, pc + 2, mp, write(mem, mp, sread(mem, mp) - number))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   286
        case '.' => print(sread(mem, mp).toChar); compute4(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   287
        case '[' => if (sread(mem, mp) == 0) compute4(pg, tb, tb(pc), mp, mem) else compute4(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   288
        case ']' => if (sread(mem, mp) != 0) compute4(pg, tb, tb(pc), mp, mem) else compute4(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   289
        case '*' => compute4(pg, tb, pc + 1, mp, write(mem, mp, sread(mem, mp) * sread(mem, mp - 1)))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   290
        case '@' => compute4(pg, tb, pc + 1, mp, write(mem, mem(mp), sread(mem, mp - 1)))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   291
        case '#' => print(sread(mem, mp)); compute4(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   292
        case '0' => compute4(pg, tb, pc + 1, mp, write(mem, mp, 0))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   293
        case _ => compute4(pg, tb, pc + 1, mp, mem)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   294
      }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   295
    }
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   296
    case _ => mem
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   297
  }
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   301
// should call first optimise and then combine on the input string
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   302
//
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   303
def run4(pg: String, m: Mem = Map()) = {
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   304
  val processed_prog = combine(optimise(pg))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   305
  compute4(processed_prog, jtable(processed_prog), 0, 0, m)
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
// testcases
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   310
// combine(optimise(load_bff("./main5/benchmark.bf"))) // => """>A+B[<A+M>A-A]<A[[....."""
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   312
// testcases (they should now run much faster)
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   313
// time_needed(1, run4(load_bff("./main5/benchmark.bf")))
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   314
// time_needed(1, run4(load_bff("./main5/sierpinski.bf"))) 
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
   315
// time_needed(1, run4(load_bff("./main5/mandelbrot.bf")))
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
286
5c57c407e27b updated
Christian Urban <urbanc@in.tum.de>
parents: 250
diff changeset
   318
}