당신의 작업은 간단합니다 : 검은 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 개 라인은 난수 생성기를 구성하여 16 개의 랜덤 3 비트 숫자 (즉, 0 ~ 7 범위)를 플레이 필드의 10 번째 라인에 저장합니다. 네 번째 줄은 PBM 헤더를 작성하고 마지막 줄은 이미지의 픽셀을 생성합니다. 이는 픽셀이 출력 될 때 16 개의 난수를 카운트 다운하여 수행됩니다. 특정 열에 해당하는 숫자가 0에 도달하면 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();}(일 변경 : 정적 제거, 자바 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
화면에 이미지를 그립니다.
두 가지 접근 방식이 동일한 바이트 범위로 렌더링됩니다.
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, 86105 바이트
즉시 창 사용
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