mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.3 KiB
35 lines
1.3 KiB
![]()
5 years ago
|
## brainfuck
|
||
|
|
||
|
### Instructions
|
||
|
|
||
![]()
5 years ago
|
Write a `Brainfuck` interpreter program.
|
||
![]()
5 years ago
|
The source code will be given as first parameter.
|
||
![]()
5 years ago
|
The code will always be valid, with less than 4096 operations.
|
||
![]()
5 years ago
|
`Brainfuck` is a minimalist language. It consists of an array of bytes (in this exercice 2048 bytes) all initialized with zero, and with a pointer to its first byte.
|
||
![]()
5 years ago
|
|
||
|
Every operator consists of a single character :
|
||
5 years ago
|
|
||
5 years ago
|
- '>' increment the pointer
|
||
|
- '<' decrement the pointer
|
||
|
- '+' increment the pointed byte
|
||
|
- '-' decrement the pointed byte
|
||
|
- '.' print the pointed byte on standard output
|
||
|
- '[' go to the matching ']' if the pointed byte is 0 (loop start)
|
||
|
- ']' go to the matching '[' if the pointed byte is not 0 (loop end)
|
||
![]()
5 years ago
|
|
||
|
Any other character is a comment.
|
||
|
|
||
![]()
5 years ago
|
### Usage
|
||
![]()
5 years ago
|
|
||
|
```console
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/brainfuck$ go build
|
||
|
student@ubuntu:~/[[ROOT]]/brainfuck$ ./brainfuck "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>." | cat -e
|
||
![]()
5 years ago
|
Hello World!$
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/brainfuck$ ./brainfuck "+++++[>++++[>++++H>+++++i<<-]>>>++\n<<<<-]>>--------.>+++++.>." | cat -e
|
||
![]()
5 years ago
|
Hi$
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/brainfuck$ ./brainfuck "++++++++++[>++++++++++>++++++++++>++++++++++<<<-]>---.>--.>-.>++++++++++." | cat -e
|
||
5 years ago
|
abc$
|
||
![]()
4 years ago
|
student@ubuntu:~/[[ROOT]]/brainfuck$ ./brainfuck
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/brainfuck$
|
||
![]()
5 years ago
|
```
|