1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:44:39 -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
func main() {
var a [30000]byte;
prog := "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";
p := 0;
pc := 0;
for {
switch prog[pc] {
case '>':
p++;
case '<':
p--;
case '+':
a[p]++;
case '-':
a[p]--;
case '.':
print string(a[p]);
case '[':
if a[p] == 0 {
for nest := 1; nest > 0; pc++ {
if prog[pc+1] == ']' {
nest--;
}
if prog[pc+1] == '[' {
nest++;
}
}
}
case ']':
if a[p] != 0 {
for nest := -1; nest < 0; pc-- {
if prog[pc-1] == ']' {
nest--;
}
if prog[pc-1] == '[' {
nest++;
}
}
}
default:
return;
}
pc++;
}
var a [30000]byte;
prog := "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";
p := 0;
pc := 0;
for {
switch prog[pc] {
case '>':
p++;
case '<':
p--;
case '+':
a[p]++;
case '-':
a[p]--;
case '.':
print string(a[p]);
case '[':
if a[p] == 0 {
for nest := 1; nest > 0; pc++ {
switch prog[pc+1] {
case ']':
nest--;
case '[':
nest++;
}
}
}
case ']':
if a[p] != 0 {
for nest := -1; nest < 0; pc-- {
switch prog[pc-1] {
case ']':
nest--;
case '[':
nest++;
}
}
}
default:
return;
}
pc++;
}
}