Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
55
Task/Execute-Brain-/Go/execute-brain-.go
Normal file
55
Task/Execute-Brain-/Go/execute-brain-.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// example program is current Brain**** solution to
|
||||
// Hello world/Text task. only requires 10 bytes of data store!
|
||||
bf(10, `++++++++++[>+>+++>++++>+++++++>++++++++>+++++++++>++
|
||||
++++++++>+++++++++++>++++++++++++<<<<<<<<<-]>>>>+.>>>
|
||||
>+..<.<++++++++.>>>+.<<+.<<<<++++.<++.>>>+++++++.>>>.+++.
|
||||
<+++++++.--------.<<<<<+.<+++.---.`)
|
||||
}
|
||||
|
||||
func bf(dLen int, is string) {
|
||||
ds := make([]byte, dLen) // data store
|
||||
var dp int // data pointer
|
||||
for ip := 0; ip < len(is); ip++ {
|
||||
switch is[ip] {
|
||||
case '>':
|
||||
dp++
|
||||
case '<':
|
||||
dp--
|
||||
case '+':
|
||||
ds[dp]++
|
||||
case '-':
|
||||
ds[dp]--
|
||||
case '.':
|
||||
fmt.Printf("%c", ds[dp])
|
||||
case ',':
|
||||
fmt.Scanf("%c", &ds[dp])
|
||||
case '[':
|
||||
if ds[dp] == 0 {
|
||||
for nc := 1; nc > 0; {
|
||||
ip++
|
||||
if is[ip] == '[' {
|
||||
nc++
|
||||
} else if is[ip] == ']' {
|
||||
nc--
|
||||
}
|
||||
}
|
||||
}
|
||||
case ']':
|
||||
if ds[dp] != 0 {
|
||||
for nc := 1; nc > 0; {
|
||||
ip--
|
||||
if is[ip] == ']' {
|
||||
nc++
|
||||
} else if is[ip] == '[' {
|
||||
nc--
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue