main_solution5/bf.scala
changeset 429 126d0e47ac85
parent 424 daf561a83ba6
child 430 274c865b3878
--- a/main_solution5/bf.scala	Tue Nov 01 15:03:48 2022 +0000
+++ b/main_solution5/bf.scala	Wed Nov 02 13:22:59 2022 +0000
@@ -111,7 +111,12 @@
 def run(prog: String, m: Mem = Map()) = compute(prog, 0, 0, m)
 
 
+def generate(msg: List[Char]) : String = msg match {
+  case Nil => ""
+  case c::cs => s"${"+" * c.toInt}.[-]" ++ generate(cs) 
+}
 
+//println(generate("Hello World\n".toList))
 
 
 // some sample bf/bf++-programs collected from the Internet
@@ -212,4 +217,7 @@
 
 
 //M5a.run(M5a.load_bff("mandelbrot.bf"))
-M5a.run(M5a.load_bff("collatz.bf"))
+//M5a.run(M5a.load_bff("collatz.bf"))
+
+println(M5a.generate("ABC".toList))
+M5a.run(M5a.generate("Hello World\n".toList))
\ No newline at end of file