3

I've been working on this programming challenge: http://www.codeabbey.com/index/task_view/summing-up

Which basically states:

Input data has two values A and B in the single line.
Output should have the sum A+B printed into it.
Additionally after the stop the program should have values A, B, A+B in the cells 0, 1 and 2 respectively.

So for example input would look like this:

9 26

Now, I think I be misunderstanding either the problem or the solution because I believe the solution is supposed to be 9 26 35 where 9, 26, and 35 are all in their own cells.

My solution returns 9 26 35 and I believe in the correct cells (0,1, and 2 respectfully) but I am getting the answer wrong. Can anyone please look at the problem and my code and tell me where I am going wrong?

Code:

;:>;:><[-<+>]<:
Vale
  • 1,003
  • 1
  • 9
  • 22

2 Answers2

1

I tried plugging this into a couple of online brainfuck interpreters. There is one here:

http://copy.sh/brainfuck/

and another here:

http://esoteric.sange.fi/brainfuck/impl/interp/i.html

In both cases, I needed to change your character set slightly --> : becomes . and ; becomes ,

The output from both was

    9 Y

Notice that 35 - 9 = 24, and Y is the 24th letter of the alphabet. I think you are outputting the number "35" and having it interpretted as a letter.

I would try changing the program so that your output is literally single digits of the answer -- ie, output a 3, then output a 5, instead of outputting a numerical "35" (but leave the numerical value in cell 2 at the end). In other words, your text output should be a formatted version of the values in memory, rather than just outputting the numerical values directly.

Barry Gackle
  • 829
  • 4
  • 17
  • I noticed other interpreters ran code differently than CodeAbbey, but I'm trying to solve it on CodeAbbey so I kept it the way it was seeing as it worked there well enough it seems. Besides that though, thank you for the suggestion, I'll change it up and see if I can get it to work. – Vale May 12 '15 at 04:13
  • 1
    I initially looked up the character set on Wikipedia, that's where I got the idea to sub in ',' and '.' It appears to just be two different dialects (I like CodeAbbeys personally -- seems a lot easier to read). – Barry Gackle May 12 '15 at 04:16
1

It sounds like the output should only have A+B printed, not A, B, and A+B, as you're doing with :.

And your result seems like it'll have A+B in cell 0, and 0 in cell 1 (essentially the same as the example code).

>< is just cancelling itself out.

Jeff Ames
  • 1,424
  • 10
  • 18