# ずんだの1桁足し算問題 Brainf**k版

てぃーびーさんずんだの1桁足し算問題をBrainf**kで実装しました。

ループの制御、複数桁の数字管理等、Brainf**kの初～中級として手頃な問題ではないかと思います。

```** ずんだの1桁足し算問題
** prepare symbol characters
+++[->+++++++<]
>[->P++>E+++>C++++++<<<]
>P+>E-->>

** double loop
i+++++++++[-
>>j+++++++++[-
** main
* memory layout: PECi_j
*  P E C: character code for PLUS EQUAL TILDE respectively
*  i j: loop counters from 8 downto 0

** create several numbers from i j
<<i[->+>>S->>I->>S-<<<<<<<]>[-<+>]
>j[-<+>>S->>>J->S-<<<<<]
++++++++++[->S++>>I+>J+>S++<<<<<]

* memory layout: PECij_S_IJS
*  I J: 10 minus i/j
*  S  : I plus J

** divide by 10
>>>>>>>R++++++++++<<S--[->>R-[<r+>>>>]<[r+[->R+<]>>q+>]<<<<]

* memory layout: PECij_S_IJ_rRq
*  r q: remainder and quotient ( result of the division )
*  R: 10 minus r

** digit compaction and replacement
>>>q[+[-<<<+>>>]<R[-]<r+>>]  ( if q is not zero )
<R[[-]<r+[-<+>]>]            ( else             )

* memory layout: PECij_S_IJD(D)
*  D: created digit(s) of S minus 2 through the division
*  notice: I J D are all larger by 1 than they are meant to be

** convert numbers to characters and print
<<<<<<S<++++++[->>>I[>]<[++++++++<]<<]
>>>I-.<<<<<<<<P.>>>>>>>>>J-.<<<<<<<<E.>>>>>S--[-<<<<T.>>>>]>>>>D[-.>]

** print newline and clear temporary characters I J D then move j back
++++++++++.[[-]<]<<<[->+<]
>j]
<<i]
```