Coding Dojo

Edit on Gitlab

Brainfuck

Introduction

This exercise is based on the Brainfuck langage.

Brainfuck is an esoteric programming language created in 1993 by Urban Müller. It’s a minimalist langage composed of one character instructions while remaining Turing complete.

Problem Description

Create an interpreter, which, given a valid Brainfuck program execute it and return the memory state at the end of it.

The Brainfuck langage consists of :

The program is composed of 8 different commands :

Character Meaning
+ Increment the byte at the data pointer.
- Decrement the byte at the data pointer.
> Increment the data pointer.
< Decrement the data pointer.
. Output the byte at the data pointer (ASCII format)
, Accept one byte of input (ASCII format), storing its value in the byte at the data pointer.
[ If the byte at the data pointer is zero jump it forward to the command after the matching ] command.
] If the byte at the data pointer is nonzero jump it back to the command after the matching [ command.

Suggested steps

  1. Implement + - > < commands to manage memory.
  2. Implement . , to manage I/O.
  3. Implement [ ] to manage jump/loops.

Additional constraints