solutions5/bf.scala
changeset 264 ecd989eee8bd
parent 244 a359976a6f3e
child 290 2186e204a26c
equal deleted inserted replaced
263:5a16bcb4105e 264:ecd989eee8bd
   106 
   106 
   107 def run(prog: String, m: Mem = Map()) = compute(prog, 0, 0, m)
   107 def run(prog: String, m: Mem = Map()) = compute(prog, 0, 0, m)
   108 
   108 
   109 
   109 
   110 
   110 
   111 /*
   111 
   112 
   112 
   113 // some sample bf-programs collected from the Internet
   113 // some sample bf-programs collected from the Internet
   114 //=====================================================
   114 //=====================================================
   115 
   115 
   116 
   116 
   200       <]]++++++[>+++++++<-]>++.------------.[-]>[>>]<<[+++++[>+++++
   200       <]]++++++[>+++++++<-]>++.------------.[-]>[>>]<<[+++++[>+++++
   201       +++<-]>.<++++++[>--------<-]+<<]+<]>[<+>-]<]>>>[>>]<<[>[-]<-<
   201       +++<-]>.<++++++[>--------<-]+<<]+<]>[<+>-]<]>>>[>>]<<[>[-]<-<
   202       <]++++++++++.[-]<<<[<<]>>>+<[->[<+>-[<+>-[<+>-[<+>-[<+>-[<+>-
   202       <]++++++++++.[-]<<<[<<]>>>+<[->[<+>-[<+>-[<+>-[<+>-[<+>-[<+>-
   203       [<+>-[<+>-[<+>-[<[-]>>[-]+>+<<-]]]]]]]]]]<[>+<-]+>>]<<[<<]>>]""")
   203       [<+>-[<+>-[<+>-[<[-]>>[-]+>+<<-]]]]]]]]]]<[>+<-]+>>]<<[<<]>>]""")
   204 
   204 
       
   205 // 2 to the power of 6 
       
   206 //(example from a C-to-BF compiler at https://github.com/elikaski/BF-it)
       
   207 run(""">>[-]>[-]++>[-]++++++><<<>>>>[-]+><>[-]<<[-]>[>+<<+>-]>[<+>-]
       
   208        <><[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-]
       
   209        <[>+>+<<-]>[<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<[[-]>[-]<<[>+>
       
   210        +<<-]>>[<<+>>-][-]>[-]<<<<<[>>>>+>+<<<<<-]>>>>>[<<<<<+>>>>>-]
       
   211        <<>>[-]>[-]<<<[>>>+<<<-]>>>[<<[<+>>+<-]>[<+>-]>-]<<<>[-]<<[-]
       
   212        >[>+<<+>-]>[<+>-]<><[-]>[-]<<<[>>+>+<<<-]>>>-[<<<+>>>-]<[-]>[-]
       
   213        <<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-]<[>+>+<<-]>
       
   214        [<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<][-]>[-]<<[>+>+<<-]>>[<<+>
       
   215        >-]<<<<<[-]>>>>[<<<<+>>>>-]<<<<><>[-]<<[-]>[>+<<+>-]>[<+>-]<>
       
   216        <[-]>[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-]<<>>[-]>[-]>[-]>[-]>[-]>
       
   217        [-]>[-]>[-]>[-]>[-]<<<<<<<<<<>>++++++++++<<[->+>-[>+>>]>[+[-<+
       
   218        >]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<
       
   219        ]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++
       
   220        ++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<<><<<""")
       
   221 
   205 
   222 
   206 
   223 
   207 // a Mandelbrot set generator in brainf*** written by Erik Bosman
   224 // a Mandelbrot set generator in brainf*** written by Erik Bosman
   208 // (http://esoteric.sange.fi/brainfuck/utils/mandelbrot/)
   225 // (http://esoteric.sange.fi/brainfuck/utils/mandelbrot/)
   209 
   226 
   223   val end = System.nanoTime()
   240   val end = System.nanoTime()
   224   (end - start)/(n * 1.0e9)
   241   (end - start)/(n * 1.0e9)
   225 }
   242 }
   226 
   243 
   227 time_needed(1, run(b1))
   244 time_needed(1, run(b1))
   228 */
   245 
   229 
   246 
   230 }
   247 }