Language detail: Brainf*ck

Coverage: 5.08%
number of '+' ratings
contribution for coverage

Unsolved challenges

codes

Feed

Used modules

LL Golf Hole 6 - 10進数を2進数に基数変換する (Nested Flatten)

アドレス0に格納されている10進数を2進に変換して表示します。

1
2
3
4
>>>+<<<                               # init
[->>>[-]+>[->[-]+>]+<[<<]<]           # convert into binary
>>>[>>]<<                             # move to the end
[>>+++[->++++[-<<++++>>]<]<.[-]<-<<]  # output
リストを逆順に表示 (Nested Flatten)

アドレス0から連続して文字が格納されている場合。

1
[>]<[.<]>
LL Golf Hole 8 - 横向きのピラミッドを作る (Nested Flatten)
Brainf*ckで。
1行目は入力。2行目がプログラム本体で80byte。
ていうか2文字(LF, #)を作るのに30%消費してる。
1
2
++++
>>+++++[->+++++++>++<<]<<[->+[->+<]>[->.<<+>]>>.<<<<]>-[[->+<]>[->.<<+>]>>.<<<-]
コメントの削除 (Nested Flatten)

Brainf*ckで。入力された文字のうち、コメント(実行可能な8文字以外全部)を削除します。終了せず、ひたすら入力を待ち続けるので適当に止めてください。

Brainfuck Developerで実行する場合は複数行の入力ができませんが、[Extras] - [Set Input File ...] から入力ファイルを指定できます。すばらしいツールです。あとは言語が良けりゃぁ言うことなし。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
+[>
  ,                      # {1} = input char
  >+<                    # {2} = 1
  [->>+>+<<<]            # {3:4} = !{1}
  >>>
  >++++++[-<------->]<-  # {4} = {4} minus 43
  [                      # if {4} not 43 (plus)
    -[                   # if {4} not 44 (comma)
      -[                 # if {4} not 45 (minus)
        -[               # if {4} not 46 (dot)
          >++++[-<---->]<++
          [              # if {4} not 60 (lt)
            --[          # if {4} not 62 (gt)
              >+++++[-<------>]<+
              [          # if {4} not 91 (open)
                --[      # if {4} not 93 (close)
                  <<->>  #   then {2} = 0
                  [-]
                ]
              ]
            ]
          ]
        ]
      ]
    ]
  ]
  <<
  [>.<-]                 # if {2} then print {3}
  >[-]<<
<]
コード中の文字の頻度分析 (Nested Flatten)
Brainf*ckで。文字列を入力し、最後に「$」を入力するとヒストグラムを表示します。

コメントなし版を入力した結果
++++++++++++++++++++++++++++++++++++++
,
-------------------------
..
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

記号が多いですね(笑)
「>」69、「<」57、「+」38、角括弧30、「-」25。
入出力(.,)はごく少数。

ほとんどチューリングマシンなのでポインタの移動が多くなります。+はデータの作成に多用します。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
●コメント版
+[>                        # while ({0})  do
  +>,<                     #   {1} = 1 ; {2} = getchar()
  >                        # ** dollar check **
   >>++++++[-<++++++>]<<   #   {3} = 36 dollar
                           # ** compare {3} & {4} **
   [->>+>+<<<]             #   {@2:@3} = !{@0}
   >>>[-<<<+>>>]<<<        #   {@0} = !{@3}
   >[->->+<<]<             #   {@2} = {@2} minus {@1} ; {@3} = !{@1}
   >>>[-<<+>>]<<<          #   {@1} = !{@3}
   >>
   >+<[[-]>-<]>[-<+>]<     # ** invert result **
   [[-]<<[-]<[-]<[-]>>>>]  #   {2:1:0} = 0
   <[-]>                   #   {3} = 0
   <<
  <
  [>                       # ** count up if input char is not dollar **
   [->>>>>>+<<<<<<]        #   {8} = !{2}
   >>>>[-]>[-]>            #   {6:7} = 0 ; move to {8}
   [- [->>+<<]+>> ]        # ** extend arm to {8 plus (charcode times 2)} **
   >+<                     # ** count up **
   <<[[-]<<]               # ** reduce arm **
   <<<<
   [-]<[-]>                #   {2:1} = 0
  <]
<]                         # end   ** next char **
# show result
>>>>>>>> >>+
[
  >[[-<.>]++++++++++.[-]]<
  [->>+<<]>>+
]

●コメントなし版
+[>+>,<>>>++++++[-<++++++>]<<[->>+>+<<<]>>>[-<<<+>>>]<<<>[->->+<<]<>>>[-<<+>>]<<<>>>+<[[-]>-<]>[-<+>]<[[-]<<[-]<[-]<[-]>>>>]<[-]><<<[>[->>>>>>+<<<<<<]>>>>[-]>[-]>[-[->>+<<]+>>]>+<<<[[-]<<]<<<<[-]<[-]><]<]>>>>>>>>>>+[>[[-<.>]++++++++++.[-]]<[->>+<<]>>+]
除算・余剰を使わずに閏年 (Nested Flatten)
Brainf*ck入門しました。もう頭の中がカオスです。
割り算と if ~ else 構造がもっと簡単に使えたらいいのになぁ。。。

コメントは参考サイトに習ってつけてみました。出鱈目英語でごめんなさい。コメントの中に、つい「-」などを入れてしまい嵌ること多々。

実行結果(4桁の数字を入力し、閏年だったら1を出力)
19000
20001
20081
21000
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
●コメント版(#以降の文字と、空白・改行はコメントです。)
# {3} = input two-digit number
>> ,.<++++++[->--------<]> [->++++++++++<] ,.<++++++[->--------<]> [->+<]
<<
# {2} = input two-digit number
> ,.<++++++[->--------<]> [->++++++++++<] ,.<++++++[->--------<]> [->+<]
<
# if ( {2} not zero ) then {3} = !{2} ; pointer moves to {3}.
>> [>[-]<[->+<]]
>
# subtract 4 from {3} while ( {3} != 0 ), and if remainder exists then {5} is not 0.
>++++<                     # {4} = 4
[>                         # while ({3}) {
  [->+>+>+<<<]             #   {5:6:7} = !{4}
  >>
    >[-<<<+>>>]<           #   {4} = !{7}
    [                      #   while ({6}) {
      <<< [->>>>+<<<<]     #     {7} = !{3}
      >>>>[                #     if ({7} not zero) {
        -[-<<<<+>>>>]<<->> #       {3} = !{7} minus 1 ; decr({5})
      ]<                   #     }
      -                    #     decr({6})
    ]                      #   }
  <<
<]                         # }
# show result
<+++++++[->+++++++<]>      # {3} = 49
>>[[-]<<->>]<<             # if ({5} not zero) then decr({3})
.                          # putchar({3})


●コメントなし版
>>,.<++++++[->--------<]>[->++++++++++<],.<++++++[->--------<]>[->+<]<<>,.<++++++[->--------<]>[->++++++++++<],.<++++++[->--------<]>[->+<]<>>[>[-]<[->+<]]>>++++<[>[->+>+>+<<<]>>>[-<<<+>>>]<[<<<[->>>>+<<<<]>>>>[-[-<<<<+>>>>]<<->>]<-]<<<]<+++++++[->+++++++<]>>>[[-]<<->>]<<.
BFコンパイラー (Nested Flatten)

BFによるBFコンパイラーは、これほど簡単です:-)

種明かしは、こちら

本来であれば、,[.,]でもOKなのですが、これだとEOFが処理できません。

Dan the Brainf.cker

1
,+[-.,+]
Hello, world! (Nested Flatten)
1
+++++++++[->+++++>++++++++>+++++++++++<<<]>>.>++.+++++++..+++.<<-.[->-<]>++++.>++++++++.--------.+++.------.--------.<+.
ピラミッドを作る (Nested Flatten)
nが一桁のみの対応です。
1
>++[-<+++++>]>++++++[-<+++++++>]>++++++++[-<++++>],>++++++++[-<------>]<[->+>+<<]>>->>+<<<[->[->+<<<<.>>>]>[-<+>]<->>-[->+<<<<<<<..>>>>>>]<<<<<<.>>>>>>>[-<+>]<++<<<<<<<.>>>>]
Hello, world!その2 (Nested Flatten)
brainf*ck
1
 ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.

Index

Feed

Other

Link

Pathtraq

loading...