Brainfuck challenge

I have a any challenge. I must write brainfuck-code.

For a given number n appoint its last digit .

entrance

Input will consist of only one line in which there is only one integer n ( 1 < = n < = 2,000,000,000 ) , followed by a newline ' n' (ASCII 10).

exit

On the output has to find exactly one integer denoting the last digit of n .

example I entrance: 32 exit: 2

example II: entrance: 231231132 exit: 2

This is what I tried, but it didn't work:

+[>,]<.>++++++++++.

The last input is the newline. So you have to go two memory positions back to get the last digit of the number. And maybe you don't have to return a newline character, so the code is

,[>,]<<.

Nope sorry, real answer is

,[>,]<.

because your answer was getting one too far ;)


Depending on the interprete, you might have to escape the return key by yourself. considering the return key is ASCII: 10 , your code should look like this :

>,----- -----[+++++ +++++>,----- -----]<.

broken down :

>               | //first operation (just in case your interpreter does not
                    support a negative pointer index)
,----- -----    | //first entry if it's a return; you don't even get in the loop
[                
    +++++ +++++ | //if the value was not ASCII 10; you want the original value back
    >,          | //every next entry
    ----- ----- | //check again for the the return, 
                    you exit the loop only if the last entered value is 10
]
<.              | //your current pointer is 0; you go back to the last valid entry
                    and you display it
链接地址: http://www.djcxy.com/p/67874.html

上一篇: Brainbit与1bit记忆细胞?

下一篇: Brainfuck的挑战