Question Details

No question body available.

Tags

brainfuck

Answers (2)

Accepted Answer Available
Accepted Answer
November 2, 2025 Score: 2 Rep: 54 Quality: Medium Completeness: 50%

From what i see, your loop is driven by the "5" cell, so when input < 5 you keep decrementing past 0 and it wraps to 255. Drive the loop with the input cell instead. Stop when input hits 0, then check what's left in the "5" cell.

Tiny Brainfuck core (cell0 = numeric 0–9, cell1 = 5):

 0
  -           input--
  >-          five--
  <           back to input
]

> now on five [ if five > 0 => input < 5 / MENOR / [-] ]

< back to input > go to five again input >= 5 / MAIOR / ]>

If you're reading a digit, subtract 48 first to get 0–9, then try running this

November 17, 2025 Score: 0 Rep: 458 Quality: Low Completeness: 60%

The problem isn't the wrapping around to 255. If the input were '1' (49), and you decrement it 53 times to produce a -4, then -4 is still nonzero and it would still enter your "maior" loop. You need to write code to compare the numbers. One way would be to do a conditional decrement: 53 times, decrement the input if it's not zero yet, but if it's zero, leave it at zero. Fortunately this is easy.

>>>+++++++++.

[ 53 times [- if so then move back to second cell; decrement counter ]< +++++++++++[>+++++++.-------->----. (A) ++++++++.+++++ (I) ("maior" and "menor" means bigger and smaller in portuguese) >[-] (clean the cell 3 to avoid entering the next loop) > (Go to cell 3) (If it's empty; it means the first loop worked; so the next one won't start) (Otherwise; it will run anyway) [ (second loop ≠ 0) [-] (clean the cell 3)

] (end of the loop)