main_solution5/bfc.scala
changeset 478 191cd1de93f1
parent 463 0315d9983cd0
child 481 e03a0100ec46
equal deleted inserted replaced
477:a4e1f63157d8 478:191cd1de93f1
    58       case '>' => (pc + 1, mp + 1, mem)
    58       case '>' => (pc + 1, mp + 1, mem)
    59       case '<' => (pc + 1, mp - 1, mem)
    59       case '<' => (pc + 1, mp - 1, mem)
    60       case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
    60       case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
    61       case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
    61       case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
    62       case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
    62       case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
    63       case '['  => 
    63       case '['  => if (sread(mem, mp) == 0) (jumpRight(prog, pc + 1, 0), mp, mem) else (pc + 1, mp, mem) 
    64 	if (sread(mem, mp) == 0) (jumpRight(prog, pc + 1, 0), mp, mem) else (pc + 1, mp, mem) 
    64       case ']'  => if (sread(mem, mp) != 0) (jumpLeft(prog, pc - 1, 0), mp, mem) else (pc + 1, mp, mem) 
    65       case ']'  => 
       
    66 	if (sread(mem, mp) != 0) (jumpLeft(prog, pc - 1, 0), mp, mem) else (pc + 1, mp, mem) 
       
    67       case _ => (pc + 1, mp, mem)
    65       case _ => (pc + 1, mp, mem)
    68     }		     
    66     }		     
    69     compute(prog, new_pc, new_mp, new_mem)	
    67     compute(prog, new_pc, new_mp, new_mem)	
    70   }
    68   }
    71   else mem
    69   else mem
   141       case '>' => (pc + 1, mp + 1, mem)
   139       case '>' => (pc + 1, mp + 1, mem)
   142       case '<' => (pc + 1, mp - 1, mem)
   140       case '<' => (pc + 1, mp - 1, mem)
   143       case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
   141       case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
   144       case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
   142       case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
   145       case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
   143       case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
   146        case '['  => 
   144       case '['  => if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem) 
   147 	if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem) 
   145       case ']'  => if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem) 
   148       case ']'  => 
       
   149 	if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem) 
       
   150       case _ => (pc + 1, mp, mem)
   146       case _ => (pc + 1, mp, mem)
   151     }		     
   147     }		     
   152     compute2(pg, tb, new_pc, new_mp, new_mem)	
   148     compute2(pg, tb, new_pc, new_mp, new_mem)	
   153   }
   149   }
   154   else mem
   150   else mem
   189       case '>' => (pc + 1, mp + 1, mem)
   185       case '>' => (pc + 1, mp + 1, mem)
   190       case '<' => (pc + 1, mp - 1, mem)
   186       case '<' => (pc + 1, mp - 1, mem)
   191       case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
   187       case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
   192       case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
   188       case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
   193       case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
   189       case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
   194       case '['  => 
   190       case '['  => if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem) 
   195 	if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem) 
   191       case ']'  => if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem) 
   196       case ']'  => 
       
   197 	if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem) 
       
   198       case _ => (pc + 1, mp, mem)
   192       case _ => (pc + 1, mp, mem)
   199     }		     
   193     }		     
   200     compute3(pg, tb, new_pc, new_mp, new_mem)	
   194     compute3(pg, tb, new_pc, new_mp, new_mem)	
   201   }
   195   }
   202   else mem
   196   else mem
   276       case '>' => (pc + 2, mp + (pg(pc + 1) - '@'), mem)
   270       case '>' => (pc + 2, mp + (pg(pc + 1) - '@'), mem)
   277       case '<' => (pc + 2, mp - (pg(pc + 1) - '@'), mem)
   271       case '<' => (pc + 2, mp - (pg(pc + 1) - '@'), mem)
   278       case '+' => (pc + 2, mp, write(mem, mp, sread(mem, mp) + (pg(pc + 1) - '@')))
   272       case '+' => (pc + 2, mp, write(mem, mp, sread(mem, mp) + (pg(pc + 1) - '@')))
   279       case '-' => (pc + 2, mp, write(mem, mp, sread(mem, mp) - (pg(pc + 1) - '@')))
   273       case '-' => (pc + 2, mp, write(mem, mp, sread(mem, mp) - (pg(pc + 1) - '@')))
   280       case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
   274       case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
   281        case '['  => 
   275       case '['  => if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem) 
   282 	if (sread(mem, mp) == 0) (tb(pc), mp, mem) else (pc + 1, mp, mem) 
   276       case ']'  => if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem) 
   283       case ']'  => 
       
   284 	if (sread(mem, mp) != 0) (tb(pc), mp, mem) else (pc + 1, mp, mem) 
       
   285       case _ => (pc + 1, mp, mem)
   277       case _ => (pc + 1, mp, mem)
   286     }		     
   278     }		     
   287     compute4(pg, tb, new_pc, new_mp, new_mem)	
   279     compute4(pg, tb, new_pc, new_mp, new_mem)	
   288   }
   280   }
   289   else mem
   281   else mem