How to calculate the sum of 2 numbers with BrainFuck

前端 未结 7 707
独厮守ぢ
独厮守ぢ 2020-12-09 06:01

I\'m trying to write a program with BrainFuck that can read two numbers up to 9, calculate the sum of them and then print the result out, e.g. 3 & 5 give the result 8 .

相关标签:
7条回答
  • 2020-12-09 06:54

    That is what I know

    ,                           ;read character and store it in p1
    ------------------------------------------------   ;return ascii to Dec
    <                           ;move pointer to p2 (second byte)
    ,                           ;read character and store it in p2
    ------------------------------------------------ ;return ascii to Dec
    [                           ; enter loop
    -                           ; decrement p2
    >                           ; move to p1
    +                           ; increment p1
    <                           ; move to p2
    ]                           ; we exit the loop when the last cell is empty
    >                           ;go back to p1
    ++++++++++++++++++++++++++++++++++++++++++++++++     ;return Dec to ascii
    .                           ;print p1
    

    input:

    12
    

    output:

    3
    

    You should use numbers under 10 and that result under 10

    0 讨论(0)
提交回复
热议问题