Created
May 20, 2018 17:00
-
-
Save Spirans/2ec45cadf6cdaa10f848de8c2a9997af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
const bf = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>." | |
func main() { | |
cursor := 0 | |
arr := make([]byte, 1000) | |
for i := 0; i < len(bf); i++ { | |
switch bf[i] { | |
case '+': arr[cursor] += 1 | |
case '-': arr[cursor] -= 1 | |
case '>': cursor += 1 | |
case '<': cursor -= 1 | |
case '.': fmt.Printf("%c", arr[cursor]) | |
case ',': | |
var input byte | |
_, err := fmt.Scanf("%c", &input) | |
if err != nil { | |
panic(err) | |
} | |
arr[cursor] = input | |
case '[': | |
if arr[cursor] == 0 { | |
for j := i; j < len(bf); j++ { | |
if bf[j] == byte(']') { | |
i = j | |
break | |
} | |
if j == len(bf)-1 { | |
panic("Could not found ']'!") | |
} | |
} | |
} | |
case ']': | |
if arr[cursor] != 0 { | |
for j := i; j > 0 ; j-- { | |
if bf[j] == byte('[') { | |
i = j | |
break | |
} | |
if j == 0 { | |
panic("Could not found '['!") | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment