solutions5/bf.scala
changeset 329 8a34b2ebc8cc
parent 292 a52987bf44e1
child 336 25d9c3b2bc99
--- a/solutions5/bf.scala	Tue Dec 03 11:07:09 2019 +0000
+++ b/solutions5/bf.scala	Mon Jan 27 10:18:13 2020 +0000
@@ -1,13 +1,15 @@
 // Part 1 about an Interpreter for the Brainf*** language
 //========================================================
 
+
 object CW10a {  
 
-type Mem = Map[Int, Int]
+import io.Source
+import scala.util._
 
 
-import io.Source
-import scala.util._
+type Mem = Map[Int, Int]
+
 
 // (1) Write a function that takes a file name as argument and
 // and requests the corresponding file from disk. It returns the
@@ -92,6 +94,7 @@
       case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
       case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
       case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
+      //case ',' => (pc + 1, mp, write(mem, mp, scala.io.StdIn.readByte()))
       case '['  => 
 	if (sread(mem, mp) == 0) (jumpRight(prog, pc + 1, 0), mp, mem) else (pc + 1, mp, mem) 
       case ']'  => 
@@ -173,6 +176,7 @@
     >>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]
     <<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]""")
 
+
 //collatz numbers (needs a number to be typed in)
 run(""">,[[----------[
       >>>[>>>>]+[[-]+<[->>>>++>>>>+[>>>>]++[->+<<<<<]]<<<]
@@ -244,3 +248,4 @@
 */
 
 }
+