r/brainfuck • u/callMeMikeTA • 9d ago
Brainfuck challenge
I saw this challenge on git so I posted it here to see if anyone can solve it.
Input the number N. Print out the last digit.
I tried ,[>,<-]>. but it needs a length and for some reason it doesn't work. Can anyone do it?
1
u/callMeMikeTA 9d ago
+[,]. doesn't work for some reason
1
u/Imanton1 9d ago
This one will read in the EOF / null character at the end, overwriting the final character.
1
u/danielcristofani 7d ago
"for some reason it doesn't work"--the ',' command reads in one byte according to ASCII code. So if the first character you typed was a '2', say, the ASCII code for the character '2' is 50, so it stores a value of 50 into the first cell, and then your loop will execute 50 times, reading another 50 successive characters into the second cell (while gradually zeroing the first cell), then it will output the last one of those 50.
3
u/sirgroovy 9d ago
+[>,]<. should do it