168 // memory at the current location to 0. In the compute3 and run3 functions |
168 // memory at the current location to 0. In the compute3 and run3 functions |
169 // below you implement this command by writing the number 0 to mem(mp), |
169 // below you implement this command by writing the number 0 to mem(mp), |
170 // that is write(mem, mp, 0). |
170 // that is write(mem, mp, 0). |
171 // |
171 // |
172 // The easiest way to modify a string in this way is to use the regular |
172 // The easiest way to modify a string in this way is to use the regular |
173 // expression """[^<>+-.\[\]@*#]""", which recognises everything that is |
173 // expression """[^<>+-.\[\]""", which recognises everything that is |
174 // not a bf-command and replace it by the empty string. Similarly the |
174 // not a bf-command and replace it by the empty string. Similarly the |
175 // regular expression """\[-\]""" finds all occurences of [-] and |
175 // regular expression """\[-\]""" finds all occurences of [-] and |
176 // by using the Scala method .replaceAll you can repplace it with the |
176 // by using the Scala method .replaceAll you can repplace it with the |
177 // string "0" standing for the new bf-command. |
177 // string "0" standing for the new bf-command. |
178 |
178 |
179 def optimise(s: String) : String = { |
179 def optimise(s: String) : String = { |
180 s.replaceAll("""[^<>+-.\[\]@*#]""","") |
180 s.replaceAll("""[^<>+-.\[\]]""","") |
181 .replaceAll("""\[-\]""", "0") |
181 .replaceAll("""\[-\]""", "0") |
182 } |
182 } |
183 |
183 |
184 |
184 |
185 def compute3(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = { |
185 def compute3(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = { |