C, 85100 바이트
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);
}
업데이트 :
- OP는 각 실행마다 출력이 변경되고 15 바이트가
srand(time(0))
( :(
)