Programming contests

DEIK Regionális Programozó Csapatverseny, középiskolai kategória, 2023. december 3.

December 3, 2023, 10:00 AM – December 3, 2023, 3:30 PM

Brainf.ck

Every programmer heard about the "classical" programming languages (C, C++, C#, Java, Python,...), however not many know about the so-called "esoteric" languages. Many of these were created for the entertainment of the creator, or for "flexing" purposes. One of such language is the famous brainf.ck language. Your task is to create a compiler/interpreter for this language which is able to run the codes written in brainf.ck. The rules of the language:

  • The code runs on a circular tape which is separated into cells. The first cell has an index of 0. and the indexing grows by 1. By default every cells has as an initial 0 as a value and can hold numbers between 0 and 255 (one byte). There is a "reading head" hovering above the tape which determines the actual cell what we are working with right now. This head is at the 0th position at the start. Circularity means that before the first cell we have the last one and after the last one the head jumps back to the beginning.
  • Indexing of the cells starts at 0 and increases by 1.
  • The code can only contain the following characters:
    • < and > characters: these symbols are moving the head one step to the left or right
    • + and - characters: these symbols are increasing/decreasing the current cells' value by 1 in a circular manner: before 0 we have 255 and after 255 we have 0.
    • . symbol which prints out the value of the current cell onto the screen
    • ,number (e.g. ,013 or ,240 - the , character is always followed by a number and for easier input this number is always 3 digits long: 001, 010, 100, etc.) symbol which sets the current cells' value to the given number. The number is always between 0 and 255 (both endpoints are included). (Note: in the official implementation we only have the , character which stops the execution and waits for a user-input. However in our case this is impossible to implement, so we had to "improvize").
    • [ character: if the value of the current cell is 0, then it searches the "closing" ] pair and continues the code execution from this point. If the value of the cell is not 0, then we just simply continue to evaluate the code. The reading head is not moved.
    • ] character: if the value of the current cell is not 0, then we "jump back" to the opening [ character in our code. If the value is 0, then we just simply continue to evaluate the code. The reading head is not moved.

Input

The input is one single line which contains a t string. This is the "program-code". Each character/character combination in this code is the ones which are given in the ruleset above.

Output

The output is one single line which is the output of the code. Each number is one of the 0,...,255 numbers, separated by a single space character. Do not set the number of digits to 3 if not needed (so 5 remains 5, 12 remains 12, 123 remains 123, etc.).

Restrictions

  • the length of the tape is 100
  • the code does not contain infinite loops
  • the length of the code is at most 500 characters

Example

2+5 = 7 Input:
  1. ++.>+++++.[<+>-]<.>.
download as text file Output:
  1. 2 5 7 0
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024