I have a challenge to write obfuscated code in the brainfuck language to do the following:
For a given number n output its last digit.
input
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).
output
On the output, has to find exactly one integer denoting the last digit of n.
example I input: 32 output: 2
example II: input: 231231132 output: 2
This is what I tried, but it didn't work:
+[>,]<.>++++++++++.
The problem is that you're telling the loop to terminate when the input is 0.
The input is never 0, the ASCII for newline is 10 so that's what you'll need to use.
This code should work. In reality, this code doesn't care at all if you've given it a number, it just returns the last character before the first newline it finds.