main_templates5/bf.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Thu, 13 Jan 2022 12:55:03 +0000
changeset 423 e9d14d58be3c
parent 400 e48ea8300b2d
child 428 cdfa6a293453
permissions -rw-r--r--
test
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
399
b17a98b0c52f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
     1
// Main Part 5 about an Interpreter for 
b17a98b0c52f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
     2
// the Brainf*** language
285
bd9d142d2cd8 updated
Christian Urban <urbanc@in.tum.de>
parents: 231
diff changeset
     3
//==============================================
bd9d142d2cd8 updated
Christian Urban <urbanc@in.tum.de>
parents: 231
diff changeset
     4
bd9d142d2cd8 updated
Christian Urban <urbanc@in.tum.de>
parents: 231
diff changeset
     5
399
b17a98b0c52f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
     6
object M5a {
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
399
b17a98b0c52f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
     9
// representation of BF memory 
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
type Mem = Map[Int, Int]
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
// (1) Write a function that takes a file name as argument and
400
e48ea8300b2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 399
diff changeset
    15
// and requests the corresponding file from disk. It returns the
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
// content of the file as a String. If the file does not exists,
400
e48ea8300b2d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 399
diff changeset
    17
// the function should return the empty string.
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
import io.Source
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
import scala.util._
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 338
diff changeset
    22
def load_bff(name: String) : String = ???
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
// (2) Complete the functions for safely reading  
399
b17a98b0c52f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
    27
// and writing brainf*** memory. Safely read should
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
// Return the value stored in the Map for a given memory
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
// pointer, provided it exists; otherwise it Returns 0. The
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
// writing function generates a new Map with the
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
// same data, except at the given memory pointer the
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
// value v is stored.
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 338
diff changeset
    35
def sread(mem: Mem, mp: Int) : Int = ???
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 338
diff changeset
    37
def write(mem: Mem, mp: Int, v: Int) : Mem = ???
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
// (3) Implement the two jumping instructions in the 
399
b17a98b0c52f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
    42
// brainf*** language. In jumpRight, given a program and 
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
// a program counter move the program counter to the right 
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
// until after the *matching* ]-command. Similarly, 
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
// jumpLeft implements the move to the left to just after
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
// the *matching* [-command.
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 338
diff changeset
    48
def jumpRight(prog: String, pc: Int, level: Int) : Int = ???
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 338
diff changeset
    50
def jumpLeft(prog: String, pc: Int, level: Int) : Int = ???
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
// testcases
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
//jumpRight("""--[..+>--],>,++""", 3, 0)         // => 10
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
//jumpLeft("""--[..+>--],>,++""", 8, 0)          // => 3
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
//jumpRight("""--[..[+>]--],>,++""", 3, 0)       // => 12
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
//jumpRight("""--[..[[-]+>[.]]--],>,++""", 3, 0) // => 18
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
//jumpRight("""--[..[[-]+>[.]]--,>,++""", 3, 0)  // => 22 (outside)
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
//jumpLeft("""[******]***""", 7, 0)              // => -1 (outside)
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
399
b17a98b0c52f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
    63
// (4) Complete the compute function that interprets (runs) a brainf***
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
// program: the arguments are a program (represented as a string), a program 
399
b17a98b0c52f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
    65
// counter, a memory counter and a brainf*** memory. It Returns the
b17a98b0c52f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
    66
// memory at the stage when the execution of the brainf*** program
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
// finishes. The interpretation finishes once the program counter
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
// pc is pointing to something outside the program string.
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
// If the pc points to a character inside the program, the pc, 
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
// memory pointer and memory need to be updated according to 
399
b17a98b0c52f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
    71
// rules of the brainf*** language. Then, recursively, the compute 
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
// function continues with the command at the new program
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
// counter. 
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
//
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
// Implement the run function that calls compute with the program
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
// counter and memory counter set to 0.
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 338
diff changeset
    79
def compute(prog: String, pc: Int, mp: Int, mem: Mem) : Mem = ???
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 338
diff changeset
    81
def run(prog: String, m: Mem = Map()) = ???
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
399
b17a98b0c52f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
    85
// some sample bf-programs collected from the Internet
b17a98b0c52f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
    86
//=====================================================
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
    89
// some contrived (small) programs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
    90
//---------------------------------
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
// clears the 0-cell
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
    93
//run("[-]", Map(0 -> 100))    // Map will be 0 -> 0
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
    95
// moves content of the 0-cell to 1-cell
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
    96
//run("[->+<]", Map(0 -> 10))  // Map will be 0 -> 0, 1 -> 10
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
// copies content of the 0-cell to 2-cell and 4-cell
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   100
//run("[>>+>>+<<<<-]", Map(0 -> 42))    // Map(0 -> 0, 2 -> 42, 4 -> 42)
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
// prints out numbers 0 to 9
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   104
//run("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""")
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   105
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
// some more "useful" programs
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   108
//-----------------------------
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
// hello world program 1
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   111
//run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   112
//       ..+++.>>.<-.<.+++.------.--------.>>+.>++.""")
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
// hello world program 2
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   115
//run("""++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>+
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   116
//       +.<<+++++++++++++++.>.+++.------.--------.>+.>.""")
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   118
// hello world program 3
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   119
//run("""+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   120
//       +++.>-.------------.<++++++++.--------.+++.------.--------.>+.""")
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   122
 
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
// draws the Sierpinski triangle
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   124
//run(load_bff("sierpinski.bf"))
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
//fibonacci numbers below 100
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   128
//run("""+++++++++++
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   129
//      >+>>>>++++++++++++++++++++++++++++++++++++++++++++
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   130
//      >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   131
//      +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   132
//      <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   133
//      -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   134
//      >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   135
//      +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   136
//      ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   137
//      <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   138
//      [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]""")
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
//outputs the square numbers up to 10000
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   141
//run("""++++[>+++++<-]>[<+++++>-]+<+[>[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   142
//       >>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   143
//       <<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]""")
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   146
// calculates 2 to the power of 6 
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   147
//(example from a C-to-BF compiler at https://github.com/elikaski/BF-it)
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   148
//run(""">>[-]>[-]++>[-]++++++><<<>>>>[-]+><>[-]<<[-]>[>+<<+>-]>[<+>-]
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   149
//       <><[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-]
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   150
//       <[>+>+<<-]>[<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<[[-]>[-]<<[>+>
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   151
//       +<<-]>>[<<+>>-][-]>[-]<<<<<[>>>>+>+<<<<<-]>>>>>[<<<<<+>>>>>-]
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   152
//       <<>>[-]>[-]<<<[>>>+<<<-]>>>[<<[<+>>+<-]>[<+>-]>-]<<<>[-]<<[-]
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   153
//       >[>+<<+>-]>[<+>-]<><[-]>[-]<<<[>>+>+<<<-]>>>-[<<<+>>>-]<[-]>[-]
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   154
//       <<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-]<[>+>+<<-]>
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   155
//       [<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<][-]>[-]<<[>+>+<<-]>>[<<+>
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   156
//       >-]<<<<<[-]>>>>[<<<<+>>>>-]<<<<><>[-]<<[-]>[>+<<+>-]>[<+>-]<>
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   157
//       <[-]>[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-]<<>>[-]>[-]>[-]>[-]>[-]>
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   158
//       [-]>[-]>[-]>[-]>[-]<<<<<<<<<<>>++++++++++<<[->+>-[>+>>]>[+[-<+
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   159
//       >]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   160
//       ]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   161
//       ++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<<><<<""")
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
// a Mandelbrot set generator in brainf*** written by Erik Bosman
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
// (http://esoteric.sange.fi/brainfuck/utils/mandelbrot/)
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   167
//
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   168
//run(load_bff("mandelbrot.bf"))
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
// a benchmark program (counts down from 'Z' to 'A')
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   172
//
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   173
//run(load_bff("benchmark.bf"))
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
338
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   175
// calculates the Collatz series for numbers from 1 to 30
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   176
//
Christian Urban <christian.urban@kcl.ac.uk>
parents: 285
diff changeset
   177
//run(load_bff("collatz.bf"))
230
bebe34c975a8 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
285
bd9d142d2cd8 updated
Christian Urban <urbanc@in.tum.de>
parents: 231
diff changeset
   179
}