SPOJ CRYPTO2

From Algorithmist
Jump to navigation Jump to search

All you need to do is to add 1 to the input. Thats all no big deal, but here you are supposed to write your code in Brainf**k. Now Brainf**k is an interesting language that includes just 8 commands.

, (gets input a single character to current address of memory)

. (outputs the current memory content)

> (moves one location ahead, increments the pointer)

< (moves one location backwards)

+ (increment current content of memory by 1)

- (decrement current content of memory by 1)

[ (initializes a loop that must have an associated ']')

] (terminates the loop started by last '[')

you are given a memory array and its pointer which you can move, update or print using the above commands. This language understand only ASCII characters.

[1] you can use this as a compiler to test the code.

so if you have to print a single character 'a' (without quotes) then you have to write something like this

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.

this means you are first incrementing the value of location to 98 that is ASCII value of 'a' and then printing it.

Similarly if you want to add two numbers then you dont have any direct operator instead you have to do it by principle of counting. That makes this problem interesting and this makes this language Brainf**k.