solutions5/bf.scala
changeset 292 a52987bf44e1
parent 290 2186e204a26c
child 329 8a34b2ebc8cc
equal deleted inserted replaced
291:5372c5a538d7 292:a52987bf44e1
   114 
   114 
   115 
   115 
   116 // first some contrived (small) programs
   116 // first some contrived (small) programs
   117 
   117 
   118 // clears the 0-cell
   118 // clears the 0-cell
   119 run("[-]", Map(0 -> 100))    // Map will be 0 -> 0
   119 //run("[-]", Map(0 -> 100))    // Map will be 0 -> 0
   120 
   120 
   121 // copies content of the 0-cell to 1-cell
   121 // copies content of the 0-cell to 1-cell
   122 run("[->+<]", Map(0 -> 10))  // Map will be 0 -> 0, 1 -> 10
   122 //run("[->+<]", Map(0 -> 10))  // Map will be 0 -> 0, 1 -> 10
   123 
   123 
   124 
   124 
   125 // copies content of the 0-cell to 2-cell and 4-cell
   125 // copies content of the 0-cell to 2-cell and 4-cell
   126 run("[>>+>>+<<<<-]", Map(0 -> 42))
   126 //run("[>>+>>+<<<<-]", Map(0 -> 42))
   127 
   127 
   128 
   128 
   129 // prints out numbers 0 to 9
   129 // prints out numbers 0 to 9
   130 run("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""")
   130 //run("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""")
   131 
   131 
   132 
   132 
   133 // some more "useful" programs
   133 // some more "useful" programs
   134 
   134 
   135 // hello world program 1
   135 // hello world program 1
   136 run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
   136 //run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
   137        ..+++.>>.<-.<.+++.------.--------.>>+.>++.""")
   137 //       ..+++.>>.<-.<.+++.------.--------.>>+.>++.""")
   138 
   138 
   139 // hello world program 2
   139 // hello world program 2
   140 run("""++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>+
   140 //run("""++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>+
   141        +.<<+++++++++++++++.>.+++.------.--------.>+.>.""")
   141 //       +.<<+++++++++++++++.>.+++.------.--------.>+.>.""")
   142 
   142 
   143 // hello world program 3
   143 // hello world program 3
   144 run("""+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..
   144 //run("""+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..
   145        +++.>-.------------.<++++++++.--------.+++.------.--------.>+.""")
   145 //       +++.>-.------------.<++++++++.--------.+++.------.--------.>+.""")
   146 
   146 
   147  
   147  
   148 // draws the Sierpinski triangle
   148 // draws the Sierpinski triangle
   149 run("""++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[
   149 //run("""++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[
   150       ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
   150 //      ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
   151       ]>.>+[>>]>+]""")
   151 //      ]>.>+[>>]>+]""")
   152 
   152 
   153 run(load_bff("sierpinski.bf"))
   153 //run(load_bff("sierpinski.bf"))
   154 
   154 
   155 
   155 
   156 //fibonacci numbers below 100
   156 //fibonacci numbers below 100
   157 run("""+++++++++++
   157 //run("""+++++++++++
   158       >+>>>>++++++++++++++++++++++++++++++++++++++++++++
   158 //      >+>>>>++++++++++++++++++++++++++++++++++++++++++++
   159       >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
   159 //      >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
   160       +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
   160 //      +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
   161       <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
   161 //      <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
   162       -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
   162 //      -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
   163       >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
   163 //      >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
   164       +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
   164 //      +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
   165       ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
   165 //      ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
   166       <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
   166 //      <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
   167       [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]""")
   167 //      [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]""")
   168 
   168 
   169 
   169 /*
   170 //outputs the square numbers up to 10000
   170 //outputs the square numbers up to 10000
   171 run("""++++[>+++++<-]>[<+++++>-]+<+[
   171 run("""++++[>+++++<-]>[<+++++>-]+<+[
   172     >[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+
   172     >[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+
   173     >>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]
   173     >>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]
   174     <<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]""")
   174     <<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]""")
   239   val end = System.nanoTime()
   239   val end = System.nanoTime()
   240   (end - start)/(n * 1.0e9)
   240   (end - start)/(n * 1.0e9)
   241 }
   241 }
   242 
   242 
   243 time_needed(1, run(b1))
   243 time_needed(1, run(b1))
   244 
   244 */
   245 
   245 
   246 }
   246 }