~jacksonchen666/brainfuck_interpreter

beb214e8f477efcd63c92906841b9f25ccf9b9c5 — Jackson Chen 1 year, 1 month ago 0b43faf
refactor < instruction
1 files changed, 5 insertions(+), 3 deletions(-)

M brainfuck.go
M brainfuck.go => brainfuck.go +5 -3
@@ 5,7 5,6 @@ import (
	"errors"
	"fmt"
	"log"
	"math"
	"os"
	"regexp"



@@ 68,8 67,11 @@ func (ps *ProgramState) Step() error {
	case '-':
		currentMemory--
	case '<':
		// oh no, a float on an int
		ps.memoryPointer = int(math.Max(float64(ps.memoryPointer-1), 0))
		newMemPointer := ps.memoryPointer - 1
		if newMemPointer < 0 {
			newMemPointer = 0
		}
		ps.memoryPointer = newMemPointer
	case '>':
		ps.memoryPointer++
	case '.':