How to calculate the sum of 2 numbers with BrainFuck

前端 未结 7 751
独厮守ぢ
独厮守ぢ 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:32

    I've created a solution that can add ANY NUMBER OF NUMBERS with ANY NUMBER OF DIGITS:

    ,[+>,]>++++++++[<<[------<]>[>]>-]<<[++++[----[<]<+[<+<+>>-]<<[>>+<<
    -]>[<<<[<<]+[>>]>-]>>>>[>]<-[[<]<<<<<[<<]>>>+>[>>]>>>>[>]<-]<[<]<<<<<[<<]>>[[-]>
    >]>>>>[>]>+<]>-[<<[<]<[-]>>[>]>+]<<]<[-]<->>>>>->+[[-]>+>[<]<]<->>+>->+[>>+]<<[+
    [--[>+>+<<-]>>[<<+>>-]>+<<[>++++++++++<[->-[>>]<<<]>>>>[<<<----------<<+>>>>]<]>
    >[-]<<<[[-]<[-]<<[->>>>>+<<<<<]]<]<]>>>>>>>>>>[<<]>>[+[->++++++++[<++++++>-]<.[-
    ]]>>]
    

    For example:

    input:  13611+85399+35943
    output: 134953
    

    Make sure "Memory overflow behavior" is set to wrap.

提交回复
热议问题