あなたのタスクは簡単です:黒の16px * 8pxの長方形(幅と高さ)のランダムなピクセルを白いピクセルに置き換えるプログラムを作成します。
穴は一様にランダムである必要があり、白いピクセルが挿入された16ピクセルx 8ピクセルの画像を出力する必要があります。
列ごとに1ピクセルのみを置換(合計16置換ピクセル)
入力は一切行わず、コンピューター上の他の場所に保存されている画像に依存することはできません。
これはコードゴルフなので、バイト数が最も短いプログラムが勝ちます!
あなたのタスクは簡単です:黒の16px * 8pxの長方形(幅と高さ)のランダムなピクセルを白いピクセルに置き換えるプログラムを作成します。
穴は一様にランダムである必要があり、白いピクセルが挿入された16ピクセルx 8ピクセルの画像を出力する必要があります。
列ごとに1ピクセルのみを置換(合計16置換ピクセル)
入力は一切行わず、コンピューター上の他の場所に保存されている画像に依存することはできません。
これはコードゴルフなので、バイト数が最も短いプログラムが勝ちます!
回答:
8tE2$r&S1=3YG
例(MATLAB上で実行するMATLコンパイラーを使用):
または、MATL Onlineでお試しください!(最初に実行されない場合は、[実行]をもう一度押すか、ページを更新します)。画像は視覚化のためにオンラインインタープリターによって拡大縮小されることに注意してください。
これは、Octave / MATLABの回答の移植版です(そこの説明を参照)。同等のステートメントは次のとおりです。
MATL        Octave / MATLAB
----        ---------------
8tE         8,16
2$r         rand(...)
&S          [~,out]=sort(...)
1=          ...==1 
3YG         imshow(...)
[~,z]=sort(rand(8,16));imshow(z==1)
例(オクターブ上):
           rand(8,16)                  % 8×16 matrix of random values with uniform
                                       % distribution in (0,1)
[~,z]=sort(          );                % Sort each column, and for each output the
                                       % indices of the sorting. This gives an 8×16
                                       % matrix where each column contains a random
                                       % permutation of the values 1,2,...,8 
                              z==1     % Test equality with 1. This makes all values 
                                       % except 1 equal to 0
                       imshow(    )    % Show image, with grey colormap
main(c){char a[138]="P5 16 8 1 ";for(srand(time(0)),c=17;--c;a[9+c+(rand()&112)]=1);write(1,a,138);}PGMイメージファイルをstdoutに書き込みます(で呼び出しますprog >out.pgm)。
ゴルフをしていないと説明:
main(c) {
    // A buffer large enough to contain the whole image,
    // pre-filled with the PGM header.
    // This is a binary greyscale (P5) image with only two levels (1),
    // Because a binary bitmap would require pixel packing.
    char a[138] = "P5 16 8 1 ";
    // c iterates from 16 to 1 over the columns
    for(
        srand(time(0)), c = 17;
        --c;
        // (rand() % 8) * 16 is equivalent to (rand() & 7) << 4
        // Since all bits are equally random, this is equivalent
        // to rand() & (7 << 4), that is rand() & 112.
        // This picks a pixel from the first column, which is then
        // offset to the correct column by c - 1 + 10
        // (10 is the length of the header).
        a[9 + c + (rand() & 112)] = 1
    )
        ; // Empty for body
    // Write the whole buffer to stdout
    write(1,a,138);
}更新:
srand(time(0))(:()まで失うことを明確にしましたfill(0);rect(0,0,15,7);stroke(-1);for(int i=0;i<16;)point(i++,random(8));
サンプル出力:
fill(0);               //sets the fill colour to black
rect(0,0,15,7);        //draws a 16*8 black rectangle
stroke(-1);            //set stroke colour to white
for(int i=0;i<16;)     // for-loop with 16 iterations
 point(i++,random(8)); //  draw a point at x-coordinate i and a random y coordinate
                       //  the colour of the point is white since that is the stroke colour
puts'P116 8';puts Array.new(16){[*[1]*7,0].shuffle}.transposeこれは、netpbm形式のイメージをstdoutに出力する完全なプログラムです。
サンプル出力:
puts'P116 8';   # output the netpbm header (P1 for black and white, 16x8)
puts            # then output the data as follows:
Array.new(16){  # make a 16-element array and for each element,
[*[1]*7,0]      # generate the array [1,1,1,1,1,1,1,0] (1=black 0=white)
.shuffle}       # shuffle the array
.transpose      # transpose the rows/columns of the 2d array (so that each column
                # has one white pixel)これにより、stdoutに書き込まれるPBMファイルが生成されます。
>030#v_\2*>>?1v
:v9\$<^!:-1\<+<
|>p1+:78+`!
>"P",1..8.28*8*v
.1-\88+%9p:!#@_>1-::88+%9g:!!
説明
上の3行は乱数ジェネレーターを構成し、プレイフィールドの10行目に16個のランダムな3ビット数(0〜7の範囲)を格納します。行4はPBMヘッダーを書き出し、最後の行は画像のピクセルを生成します。これは、ピクセルが出力されるときに16個の乱数をカウントダウンすることで実行されます。特定の列に対応する数値がゼロに達すると、0ではなく1が出力されます。
サンプル出力(ズーム):

Image[{RandomInteger@7+1,#}->1&~Array~16~SparseArray~{8,16}]
サンプル出力
説明
{RandomInteger@7+1,#}->1&~Array~16
各列の置換ルールを作成します。ランダムに選択した位置を1に置き換えます。
... ~SparseArray~{8,16}
SparseArray置換ルールからサイズ8x16のを作成します。背景は0デフォルトです。(Mathematicaは行を最初にカウントするため8x16)
Image[ ... ]
変換SparseArrayにImageオブジェクト。
77バイトバージョン
ReplacePixelValue[Image@(a=Array)[0&~a~16&,8],{#,RandomInteger@7+1}->1&~a~16]
import java.awt.*;static void l(){new Frame(){public void paint(Graphics g){int x=50;int i=16;g.setColor(Color.BLACK);g.fillRect(x,x,16,8);g.setColor(Color.WHITE);for(;i>0;i--){int y=(int)(Math.random()*8);g.drawLine(x+i,x+y,x+i,x+y);setVisible(1>0);}}}.show();}
座標系にフレームウィンドウペインが含まれているため、不安定でした...したがって、少なくとも26バイトまたは何も表示されずにバッファリングする必要があるため、x=50ビットが表示されます。
import java.awt.*;v->{new Frame(){public void paint(Graphics g){int x=50,i=16,y;g.setColor(Color.BLACK);g.fillRect(x,x,i,8);for(g.setColor(Color.WHITE);i>0;g.drawLine(x+i,x+y,x+i--,x+y),setVisible(1>0))y=(int)(Math.random()*8);}}.show();}(行われた変更:静的を削除;のJava 8のラムダを、いくつかのintよ取り外し、i=16再利用、括弧を削除するために、ループ内のものを入れて;)
                    0xA201 'Load sprite at address 201 (which is the second byte of this instruction)
0xC007 'Set register 0 to a random number from 0 to 7 (rnd & 0x7)
0xD101 'Draw sprite. x = register 1, y = register 0, height = 1
0x7101 'Add 1 to register 1
0x3110 'If register 1 is not 16...
0x1202 'Jump to second instruction
画面に画像を描画します。
同じバイト範囲にレンダリングする2つの異なるアプローチ:
grid [canvas .c -w 16 -he 8 -bg #000 -highlightt 0]
.c cr i 8 4 -i [set p [image c photo -w 16 -h 8]]
set x 0
time {$p p #FFF -t $x [expr int(rand()*8)];incr x} 16
grid [canvas .c -w 16 -he 8 -bg #000 -highlightt 0]
.c cr i 8 4 -i [set p [image c photo -w 16 -h 8]]
time {$p p #FFF -t [expr [incr x]-1] [expr int(rand()*8)]} 16
VBA Excel、86 105バイト
イミディエイトウィンドウを使用する
Cells.RowHeight=42:[a1:p8].interior.color=0:for x=0to 15:[a1].offset(rnd*7,x).interior.color=vbwhite:next
Cells.RowHeight=42:[A1:P8].Interior.Color=0:For x=0To 15:[A1].Offset(Rnd*7,x).Interior.Color=-1:Next