このリンクは非常に役立つはずです: http://esolangs.org/wiki/brainfuck_algorithms
これには、乗算のアルゴリズムと IF 条件、およびブール比較 (たとえば、ユーザーが [文字 10] を押して入力を終了したかどうかを確認するため) が含まれています。
次に、あなたがすることはこれです(私はいくつかの疑似コードを書きます。そこで説明されているアルゴリズムを使用してそれを実装するのはあなた次第です)。そのページには含まれていないため、最後にwhileループを実装する方法に関する擬似コードも提供します(ただし、それでもかなり単純です...比較的)。それぞれのキャラクターが何をしているかを正確に理解できたら、きっと驚くことでしょう :D. とにかく、ここに行きます:
AとBの2つのセルが必要です
move to B
input a character
while B is not equal to 10 (the newline character) then
subtract 48 from B ('0' is character 48, so if we subtract 48 from any digit entered we should get its value. Of course this assumes that the user only presses digit keys or enter. I'll leave it as an exercise to you to do error checking)
multiply A by 10
add B to A (you can just move B to A like this [<+>-] since you will not need B's value anymore)
move to B
input a character
ここでは、while ループの作成方法について少し説明します。次のコードがあるとしますwhile (condition) {body}
。以前に提供したリンクを使用して、条件のコードを実装できたと仮定します。条件の結果を格納するセルが必要です。これを呼び出しますC
execute condition and store result in C
start loop using [[-] (start the loop and immediately clear C)
execute loop body
execute condition and store result in C
end loop using ]