2016-12-07 11 views
0

私は、これらの数字の積を計算するために2つの数字(10より小さい)を求める頭脳プログラムを書こうとしました。計算後、結果を出力する必要があります。私のコードは次のようになります。Brainfでの乗算* ck

0 * 1 = 3 
1 * 1 = 4 
1 * 2 = 8 
2 * 1 = 5 
2 * 2 = : 

など:

++++[>++++[>+++<-]<-] writing 48/0x30/'0' in cell(2) 
    ,>,>     reading two numbers in cell(0) and cell(1) 
    [<-<->>-]    decrementing cell(0) and cell(1) by 48/0x30/'0' 
    <<      go to cell(0) 
    [      muliplication loop 
     >     go to cell(1) 
     [>+>+<<-]   move cell(1) to cell(2) and cell(3) 
     >>     go to cell(3) 
     [<<+>>-]   move cell(3) back to cell(1) 
     <<<-    decrement cell(0) 
    ] 
    ++++[>++++[>+++<-]<-] adding 48/0x30/'0' to cell(2) 
    >>.      print result 

これは本当に奇妙な結果私に与えます。もちろん

、出力は実際には次のようになります。

​​

が、私はここでそれをより読み見せたかったです。

答えて

0

いくつか検討した結果、結果を印刷可能な数値に変更すると大きなミスを犯したことがわかりました。私は一時的なカウンターセルとしてcell(1)を使用していますが、まだ値があります。だから私は結果に48/0x30/'0'を追加する前に>[-]<を挿入:

++++[>++++[>+++<-]<-] writing 48/0x30/'0' in cell(2) 
    ,>,>     reading two numbers in cell(0) and cell(1) 
    [<-<->>-]    decrementing cell(0) and cell(1) by 48/0x30/'0' 
    <<      go to cell(0) 
    [      mulitplication loop 
     >     go to cell(1) 
     [>+>+<<-]   move cell(1) to cell(2) and cell(3) 
     >>     go to cell(3) 
     [<<+>>-]   move cell(3) back to cell(1) 
     <<<-    decrement cell(0) 
    ] 
    >[-]<     set cell(1) to 0 so that it can be used as counter 
    ++++[>++++[>+++<-]<-] adding 48/0x30/'0' to cell(2) 
    >>.      print result 

ノートを、それはまだわずか10

0

本当に素晴らしいリソースがthe Esolangs page on Brainfuck algorithmsであるよりも小さい結果と正常に動作すること。あなたの主な問題が発生し、しかし

[-] 
>[-] 
>[<+>-] 
<[ 
>>[<+<<+>>>-]<<<[>>>+<<<-] 
>-] 

:だから、

temp0[-] 
temp1[-] 
x[temp1+x-] 
temp1[ 
y[x+temp0+y-]temp0[y+temp0-] 
temp1-] 

テープがtemp0のポインタで、temp0 temp1 x yのように一般的に見た場合、その結果の置換は次のようになります。そこでは、乗算は以下のように定義されます.を呼び出して出力してください。あなたの方法は、一桁の数字を出力する場合にのみ機能します。

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

The original post containing this algorithm.

:数などのセルの内容を出力するには、次のコードを使用することができます