How to calculate the sum of 2 numbers with BrainFuck

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

    I also made a program that can only handle single digit entries and answers:

    #Make the first cell (Cell 0) hold a value of 48 
    >++++ ++++
    [
    <++++ ++
    >-
    ]
    
    #Get inputs and minus 48 from each to get Decimal 
    
    ,>,
    <<
    [
    >-
    >-
    <<-
    ]
    
    #Adds the contents of Cells 1 and 2
    
    
    >
    [
    >+
    <-
    ]
    
    #Moves answer to Cell 0
    >
    [
    <+
    >-
    ]
    <
    [
    <+
    >-
     ]
    
    #Converts answer to ASCII
    >++++ ++++
    [
    <++++ ++
    >-
    ]
    <
    
    [
    <+
    >-
    ]
    <
    #Print answer
    .
    

提交回复
热议问题