1
0
mirror of https://github.com/golang/go synced 2024-11-22 06:24:38 -07:00

turn spaces to tabs

replace ifs with switch
still runs!

SVN=118947
This commit is contained in:
Rob Pike 2008-05-15 15:20:59 -07:00
parent 9119f55e6d
commit c0c30258be

View File

@ -9,47 +9,47 @@ package main
// brainfuck // brainfuck
func main() { func main() {
var a [30000]byte; var a [30000]byte;
prog := "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."; prog := "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";
p := 0; p := 0;
pc := 0; pc := 0;
for { for {
switch prog[pc] { switch prog[pc] {
case '>': case '>':
p++; p++;
case '<': case '<':
p--; p--;
case '+': case '+':
a[p]++; a[p]++;
case '-': case '-':
a[p]--; a[p]--;
case '.': case '.':
print string(a[p]); print string(a[p]);
case '[': case '[':
if a[p] == 0 { if a[p] == 0 {
for nest := 1; nest > 0; pc++ { for nest := 1; nest > 0; pc++ {
if prog[pc+1] == ']' { switch prog[pc+1] {
nest--; case ']':
} nest--;
if prog[pc+1] == '[' { case '[':
nest++; nest++;
} }
} }
} }
case ']': case ']':
if a[p] != 0 { if a[p] != 0 {
for nest := -1; nest < 0; pc-- { for nest := -1; nest < 0; pc-- {
if prog[pc-1] == ']' { switch prog[pc-1] {
nest--; case ']':
} nest--;
if prog[pc-1] == '[' { case '[':
nest++; nest++;
} }
} }
} }
default: default:
return; return;
} }
pc++; pc++;
} }
} }