How to resolve the algorithm A+B step by step in the Brainf*** programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm A+B step by step in the Brainf*** programming language
Table of Contents
Problem Statement
A+B ─── a classic problem in programming contests, it's given so contestants can gain familiarity with the online judging system being used.
Given two integers, A and B. Their sum needs to be calculated.
Two integers are written in the input stream, separated by space(s):
The required output is one integer: the sum of A and B.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm A+B step by step in the Brainf*** programming language
Source code in the brainfuc programming language
INPUT AND SUMMATION
TODO if first symbol is a minus sign print Qgo awayQ
+> initialize sum to one
++[ loop for each input ie twice
[>>,----------[----------------------[-<+>]]<] eat digits until space or newline
<[<]>>>
>[< until no next digit
---------------- subtract ascii zero minus what we subtracted above
[->++++++++++<] add ten timess that to the next digit
<[->+<]<[->+<]>> shift sum and loop counter
>>
]
<---------------- subtract as above from last digit as well
[-<<+>>] add to sum
<-
]
<- subtract original one from sum
OUTPUT
[ while a number divided by ten is bigger than zero
[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->--------->+<<[->>>+<<<]]]]]]]]]]>>>[-<<<+>>>]<<<] divide by ten
>++++++++++++++++++++++++++++++++++++++++++++++++> convert remainder to ascii digit
]
<[.<<] print ascii digits
You may also check:How to resolve the algorithm Roman numerals/Decode step by step in the OCaml programming language
You may also check:How to resolve the algorithm Factorial primes step by step in the BASIC programming language
You may also check:How to resolve the algorithm Cantor set step by step in the Action! programming language
You may also check:How to resolve the algorithm Brownian tree step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Ethiopian multiplication step by step in the Mathematica / Wolfram Language programming language