4

The problem is to check if sequence is palindrome using Brainfuck.

input is a sequance of numbers

output 0 if it is not palindorme, else 1.

I have one idea: Say, we have sequance 1 2 3 2 1. We can memorise first cell from our array in variable(do this using operation '!'),

  • then change 1 to 0(do this using operation '0'),array will be 0 2 3 2 1,
  • then we go to the end of array until we meet 0 (do this using '>[>]'),
  • then we take number from variable and get sequance 0 2 3 2 1 1.
  • Next step should be to compare two last numbers, if they are equal continue algo from begining else do something...

I do not know how to implement last step.

d40a
  • 154
  • 9

1 Answers1

2

please excuse me if I won't write the entire program in brainfuck,

This is the main idea:

  1. Read input (pointer should be at last character afterwards)
  2. memorize character
  3. Set value to 0
  4. Go to first [<]
  5. Compare to memorized character (see Brainfuck compare 2 numbers as greater than or less than)
  6. If not equal, print 1
  7. If the next (>) cell array is 0, print 0
  8. Move to pointer to end [>]
  9. Go back to step 2
Community
  • 1
  • 1
Uri Goren
  • 13,386
  • 6
  • 58
  • 110