Build a chessboard

23

3

Saw this in a PHP challenge. The objective is to make a chessboard with 64 squares (8*8) with the minimum amount of code. Simple enough, I made mine in PHP in 356 bytes (not impressive, I know) and I would like to see some other aproaches. This can be made in a language of your choice, as long as you keep it vanilla, so no imports. Smallest byte count wins.

The output should look like this:

screencap

And my code:

<table><?php
$c='black';function p($c,$n){echo'<td style="width:50px;height:50px;background:'.$c.'"></td>';if($n==1){echo"<tr>";}}for($i=1;$i<=64;$i++){if($i%8==0&&$c=="black"){$c="white";$n=1;}elseif($i%8==0&&$c=="white"){$c="black";$n=1;}elseif(isset($n)&&$n==1){$n=0;}elseif($c=="black"){$n=0;$c="white";}elseif($c=="white"){$n=0;$c="black";}p($c,$n);}

Or readable:

<table><tr>
<?php
$color = 'black';
function printcolor($color, $nl) {

    echo '<td style="width:50px; height:50px; background:' . $color . '"></td>';
    if ($nl == true) {
        echo "</tr><tr>";
    }
}
for ($i=1; $i<=64;$i++) {
    if ($i % 8 == 0 && $color == "black") {
        $color = "white";
        $nl = true;
    } elseif ($i % 8 == 0 && $color == "white") {
        $color = "black";
        $nl = true;
    } elseif (isset($nl) && $nl == true) {      
        $nl = false;
    } elseif ($color == "black") {
        $nl = false;
        $color = "white";           
        } 
    elseif ($color == "white")  {
        $nl = false;
        $color = "black";
    }       
    printcolor($color, $nl);
}

Edit:

Sorry I wasn't very specific at first:

  • Squares should have 50px * 50px except for vectorial images.
  • Output format or size is not relevant nor it needs to be an image.
  • For evaluation purposes the output must be visible such as in an image file or a screenshot
  • No libraries written after the challenge was posted

Bruno

Posted 2016-02-04T16:59:26.427

Reputation: 365

1Minimum number of pixels? I assume 64 is not sufficient? – Stewie Griffin – 2016-02-04T17:02:16.183

3Welcome to PPCG, as it stands, this challenge doesn't really have anything to do with PHP, so I changed your tags. Also, I believe your reference implementation belongs as an answer, not in your question. As Stewie brought up, you should specify the required size of the image output, as well as things like colour specifics and whether a lossy image is allowed. – FryAmTheEggman – 2016-02-04T17:04:03.243

Can the output be in any image format? – a spaghetto – 2016-02-04T17:05:51.423

Sorry for the delay, for some reason the JS on stackexchange has issues on my Google chrome. Sorry for not being very specific, it's my first post here. Image format or size is not relevant. Squares should have 50px * 50px. – Bruno – 2016-02-04T17:12:41.830

2So some ASCII-magic is not allowed? :( – Denker – 2016-02-04T17:13:07.437

This pattern is more commonly referred to as a checkerboard, this challenge doesn't really have anything to do with chess as a game.

– mınxomaτ – 2016-02-04T17:14:35.793

@DenkerAffe You could output in PPM.

– a spaghetto – 2016-02-04T17:15:34.583

@mınxomaτ Sorry, I just saw the title and instinctively added the chess tag :P I'll remove that. – a spaghetto – 2016-02-04T17:16:20.220

How will you evaluate that the program works? Online compilers don't usually allow graphic output. Also, should the upper-left square be white, or can it be black? – Luis Mendo – 2016-02-04T17:18:55.070

@DenkerAffe, for ASCII there is Chessboard pattern.

– manatwork – 2016-02-04T17:24:19.723

@LuisMendo The output must be visible, like an image file or a print screen. It should start and end with a white square – Bruno – 2016-02-04T17:24:42.330

1Are vector graphics allowed as output? – Martin Ender – 2016-02-04T17:32:09.437

1Also can there be any kind of frame around the result? – Martin Ender – 2016-02-04T17:34:39.427

@MartinBüttner Vector graphics are allowed, as long as the colors and dimensions of the squares are correct. There can be a frame around the result. – Bruno – 2016-02-04T17:41:33.500

2Define "imports"? Does using external programs in Bash count as imports? (Keep in mind that this would be a very severe restriction—even basic commands like cat are external programs.) – Doorknob – 2016-02-04T17:52:48.370

Basic commands in bash like cat are allowed. – Bruno – 2016-02-04T17:57:59.077

4How basic is basic? What is the definition of an "import"? – Doorknob – 2016-02-04T17:59:00.787

Bash suport cat outsider the box so it's valid. However if you download and include a third party library, it's not. – Bruno – 2016-02-04T18:11:49.237

@Bruno do the squares have to be black and white? Can they be black and grey for example (as long as the difference is obvious) – Blue – 2016-02-04T18:32:31.837

@muddyfish they must be b&w like a propper checkerboard :) – Bruno – 2016-02-04T18:34:07.173

@Doorknob You can't say things like this and expect us not to see it as a challenge http://codegolf.stackexchange.com/a/71111/11259 ;-)

– Digital Trauma – 2016-02-04T19:37:25.667

6It doesn't need to be an image but each square must be at least 50px? That seems self-contradictory to me. – Peter Taylor – 2016-02-04T19:48:39.683

1@Bruno Bash does not support cat "out of the box." It's an external program. It's perfectly valid to be running Bash without having cat (although it would be very, very strange). – Doorknob – 2016-02-04T20:01:34.930

1Those last 2 requirements seem unclear and contradictory as well. It doesn't have to be any particular size, nor an image, but you have to display an image. Can I return an array that can be displayed as an image? Does that array have to have a particular size, or does it simply have to display at a minimum size? – beaker – 2016-02-04T21:08:03.303

1@PeterTaylor Both the example PHP and my PowerShell answer do not output images, yet each square is 50px... – AdmBorkBork – 2016-02-04T21:53:42.680

4Programming languages here are very diverse, including some that are made specifically for golfing and have many builtin functions. Therefore, I recommend that the restriction to non-library functions be removed, and that this question instead follow the default (all imports counted in byte count; no libraries written after the challenge was posted). – lirtosiast – 2016-02-05T03:23:31.113

@Bruno, the requirement certainly becomes better, but I find that ”If you have to import it, it's not valid” ambiguous. That sounds like we can draw using ImageMagick in PHP as there no explicit import is needed, but we can not do the same in Perl, Python or Ruby as there an explicit import is needed. – manatwork – 2016-02-05T09:59:01.637

@manatwork that is correct. Imagemagic is built into PHP so it's valid. However, if you have to do something like @import('imagemagic') or @include('thisscriptwhereipasscolorsandsizeanditwilloutputmeapng.php') it's not. – Bruno – 2016-02-05T10:30:47.970

“Imagemagic is built into PHP” – Installed as separate package (php5-imagick), provided as separate library (imagick.so), configured through separate file (imagick.ini). Not so sure it is built in.

– manatwork – 2016-02-05T10:35:58.583

@manatwork i understand your point. The limitation is to prevent people from creating a library that automates the process and creating a file by simply doing generatechessboard(50,#000,#FFF) on the PHP file and thus have a 30 byte count. When you install php, imagemagic is included by default and you don't need to add any header to use it in your code so it's valid. – Bruno – 2016-02-05T10:43:48.227

Oh. I see your point. For that reason suggested @ThomasKwa to formulate in the usual way: “no libraries written after the challenge was posted”. – manatwork – 2016-02-05T10:47:27.450

@ThomasKwa Edited the description, thanks for the suggestion – Bruno – 2016-02-05T11:00:33.443

Why did you accept the Octave answer? The MATL answer is 7 bytes shorter. – Dennis – 2016-02-05T17:54:39.860

The MATL answer starts with black instead of white. I couldn't test the image but I tested it with 1 and 0 online at http://matl.tryitonline.net/#code=ODp0IStRMlwK&input= by removing the TYG

– Bruno – 2016-02-05T18:20:00.827

@Bruno The question does not state any requirement that the top-left corner is white. That answer is valid. – Mego – 2016-02-06T04:34:28.717

The screenshots suggest otherwise. In any case, I wouldn't recommend silently disqualifying an answer because you think it doesn't work. At least post a comment on the answer. – Dennis – 2016-02-06T07:02:18.163

@Mego comment #10. It should be added to the requirement but it's clearly stated – edc65 – 2016-02-06T10:57:54.567

@edc65 Comments are not binding unless they are added to the spec, because comments are transient and can disappear without warning. That's one of the things listed on the things to avoid meta post. – Mego – 2016-02-06T14:38:39.333

Answers

13

Octave, 20 18 bytes

Thanks to @Bruno for shaving off 2 bytes.

imshow(invhilb(8))

Result:

enter image description here

This answer uses a technique found here. It also relies on the automatic scaling of images in Octave depending on the size of the figure window.

beaker

Posted 2016-02-04T16:59:26.427

Reputation: 2 349

1@AlexA. I'm also not entirely convinced that the squares must be exactly 50x50 pixels, as the very next rule says "Output format or size is not relevant...". People have asked for clarification in the comments, but the question has not been updated. – beaker – 2016-02-05T02:08:23.503

Edited the question. Tested your code and it's working, so currently you have the lowest byte count :) – Bruno – 2016-02-05T10:14:01.647

Also removed the >0 and it still works so you can shave 2 bytes there – Bruno – 2016-02-05T10:16:57.297

@Bruno What? That is wild. So it's apparently clamping the values of the matrix (which are all <<0 or >>1) to 0 and 1. Thanks for the tip, I'll update! :D – beaker – 2016-02-05T15:37:39.077

Congrats on 2k! – NoOneIsHere – 2016-08-16T22:33:08.157

26

vim, 47 46 44 43

crossed out 44 is still regular 44...

iP1 400 <C-p><cr><esc>50i1<esc>YpVr0yk3PyG49PyG:m$<cr>p2GyG3P
i          enter insert mode
P1         signal to NetPPM that we're using black&white (PBM) format
400        width
<C-p>      fancy trick that inserts the other 400 for height
<cr><esc>  exit insert mode on the next line
50i1<esc>  insert 50 '1's (black)
YpVr0      insert 50 '0's (white) by duplicating the line and replacing all chars
yk         copy both lines (yank-up)
3P         paste three times; this leaves us on line two
yG         copy from line 2 to end of file (this is a full row of pixels now)
49P        we need 50 rows of pixels to make a complete "row"; paste 49 times
yG         copy the entire row of the checkerboard
:m$<cr>    move line 2 (the line we're currently on) to the end of the file
           this gives us the "alternating rows" effect
p          we're now on the last line: paste the entire row we copied earlier
2G         hop back to line 2 (beginning of image data)
yG3P       copy the entire image data, paste 3 times

Outputs in NetPPM format (PBM):

output

Doorknob

Posted 2016-02-04T16:59:26.427

Reputation: 68 138

2I love that you can complete a graphical output challenge with a text editor. Are there any other examples of PBMs from golfed vim? – ankh-morpork – 2016-02-04T23:12:06.120

1@dohaqatar7 I dunno, but I've done TikZ with vim before, so graphics in vim is a thing for sure. – Doorknob – 2016-02-04T23:38:05.373

2Wow, I never thought to try <C-p> in vim without having started typing a word... that is really handy! – Desty – 2016-02-05T15:41:34.430

16

CSS, 244 bytes

html{background:#fff}body{width:400px;height:400px;background:linear-gradient(45deg,#000 25%,transparent 25%,transparent 75%,#000 75%)0 0/100px 100px,linear-gradient(45deg,#000 25%,transparent 25%,transparent 75%,#000 75%)50px 50px/100px 100px}

html {
    background: white;
}
body {
    width: 400px;
    height: 400px;
    background:
        linear-gradient(45deg, black 25%, transparent 25%, transparent 75%, black 75%) 0px 0px / 100px 100px,
        linear-gradient(45deg, black 25%, transparent 25%, transparent 75%, black 75%) 50px 50px / 100px 100px
}

Explanation: A 100x100px diagonal linear gradient is created with four stops so that most of the gradient is transparent except for two 50px triangular corners. (See below snippet). Adding a second gradient with a 50x50px offset fills in the missing halves of the squares. Increasing the size of the body then allows the resulting pattern to repeat to fill the entire chessboard.

html {
    background: white;
}
body {
    width: 100px;
    height: 100px;
    background: linear-gradient(45deg, black 25%, transparent 25%, transparent 75%, black 75%) 0px 0px / 100px 100px
}

Neil

Posted 2016-02-04T16:59:26.427

Reputation: 95 035

Neat solution. It should work as well if you drop the last }. – insertusernamehere – 2016-02-04T19:50:45.197

Can you explain what's going on here? – flawr – 2016-02-04T19:52:44.200

@flawr I've added a second snippet showing the partial effect, I hope that helps. – Neil – 2016-02-04T20:02:43.773

This is perfect. – Not that Charles – 2016-02-04T20:45:23.680

Do you really need the html{background:#fff}? By default 99% of browsers set the background to white, afaik – Downgoat – 2016-02-05T01:48:54.030

@Doᴡɴɢᴏᴀᴛ If I don't do that then the body's background gets applied to the canvas, ruining the effect. – Neil – 2016-02-05T08:37:22.687

15

Mathematica, 34 bytes

ArrayPlot@Array[Mod[+##,2]&,{8,8}]

The output is a vector image and is surrounded in a frame.

Instead of correctly positioning 32 rectangles, we can just generate a binary matrix and make ArrayPlot work for us:

enter image description here

Martin Ender

Posted 2016-02-04T16:59:26.427

Reputation: 184 808

Nice! Thanks for posting it. – A Simmons – 2016-02-04T17:45:13.127

Looking good. Can you please explain me where do you define each square as 50px? Also, is there an online emulator where I can test it? – Bruno – 2016-02-04T17:47:31.597

@Bruno The output is a vector graphic, so there is no such thing as pixel sizes (the image has no intrinsic size - it can be scaled to and displayed at any size). That's why I asked. – Martin Ender – 2016-02-04T17:49:54.230

Ok, silly me, I was thinking SVG :) Fair enough, I'll allow it. Good work – Bruno – 2016-02-04T17:53:59.750

4Wait, GenerateChessBoardWithColorsAsParameters[ColorBlack, ColorWhite, 8, 8, 50, 50] doesn't work? ;) – Conor O'Brien – 2016-02-04T23:28:18.130

3@CᴏɴᴏʀO'Bʀɪᴇɴ It does, but that's 73 bytes. – Martin Ender – 2016-02-05T08:16:33.183

Oh? Darn. Haha! – Conor O'Brien – 2016-02-05T12:27:50.920

33 bytes: ArrayPlot[Plus~Array~{8,8}~Mod~2] – matrix89 – 2017-10-09T08:27:28.473

10

Mathematica, 81 72 55 bytes

Graphics[Rectangle/@Select[Range@8~Tuples~2,2∣Tr@#&]]

Input/Output

Image is of a previous version's evaluation, but still looks the same.

A Simmons

Posted 2016-02-04T16:59:26.427

Reputation: 4 005

8

Pure Bash (no external utilities), 133

I saw @Doorknob's comment as a bit of a challenge. Its a bit long, but here goes:

echo \# ImageMagick pixel enumeration:400,400,1,rgb
for((;x=p%400,y=p/400,c=1-(x/50^y/50)&1,p++<160000;));{
echo "$x,$y:($c,$c,$c)"
}

Output is in Imagemagick's .txt format. Note this is pure Bash. Neither Imagemagick nor any other external utilities are spawned to generate this output. However, the output may be redirected to a .txt file and viewed with the ImageMagick display utility:

enter image description here

This image format is nice because not only is it pure text, it is little more than a list of all pixels (x, y and colour value), one per line. It is a fairly simple matter to derive all pixel values arithmetically in one big loop.


Previous answer, 167

echo "\"400 400 2 1\"
\"  c white\"
\"b c black\""
printf -vf %50s
a="$f${f// /b}"
o=("\"$a$a$a$a\"" "\"${f// /b}$a$a$a$f\"")
for i in {0..399};{
echo "${o[i/50%2]}"
}

Output is in the X_PixMap text image file format, which may also be viewed with the ImageMagick display utility.

Note I've taken as much out of the XPM format as I could such that display would still accept it. I was able to take out all the boilerplate with the exception of the " double quotes around each line. No idea what other - if any - utilities will accept this.

Digital Trauma

Posted 2016-02-04T16:59:26.427

Reputation: 64 644

8

Octave, 48 bytes

​​​​​​​​​​​​​​​imwrite(kron(mod((t=0:7)+t',2),ones(50)),'.png')

This works exactly the same as my Matlab answer, but there is no spiral in Octave. Instead we use a feature that Matlab does not have: We can use the assignment of t already as an expression, and later use t again in the same expression.

(This is the rescaled version, I do not want to clutter the answers here=)

flawr

Posted 2016-02-04T16:59:26.427

Reputation: 40 560

1The top left corner should be white, not black. – Doorknob – 2016-02-04T20:28:51.143

2The output should be a checkerboard, the orientation was not specified. – flawr – 2016-02-04T20:57:46.650

2Sorry, flawr, the output should be a chessboard. A chessboard is always "Queen on her color, white on the right" (meaning the right hand of each player has a white corner square). – corsiKa – 2016-02-04T21:38:24.183

5Then imagine one player sitting to the right, one to the left. Again: this was not specified by the challenge, that is just your interpretation. – flawr – 2016-02-04T21:52:40.460

6

PowerShell + browser of your choice, 149 143 bytes

The inability to use imports is really tough, as all of the GDI calls (i.e., the stuff PowerShell uses to draw) are buried behind imports in .NET ...

"<table><tr>"+((1..8|%{$a=$_;-join(1..8|%{'<td style="width:50px;height:50px'+("",";background:#000")[($a+$_)%2]+'"></td>'})})-join'</tr><tr>')

Edit - saved six bytes thanks to @NotThatCharles

This uses two for-loops from 1..8 to generate a big-ol' HTML string, similar to the PHP example provided, and output it onto the pipeline. Each time through we calculate whether to append ;background:#000 for the black backgrounds by taking our current position on the board modulo 2.

To use, redirect the output into the file of your choice (e.g., with something like > chessboard.htm) and then launch that in the browser of your choice. For the screenshot below, I used "c.htm" and Firefox.

firefox

AdmBorkBork

Posted 2016-02-04T16:59:26.427

Reputation: 41 581

This one was unespected but I quite like it somehow :) – Bruno – 2016-02-04T18:34:43.080

white and black can be #fff and #000... but why bother specifying white? – Not that Charles – 2016-02-04T20:53:01.337

try (";background:#000","")[($a+$_)%2] instead. – Not that Charles – 2016-02-04T22:27:46.453

@NotthatCharles Durr, had my white and black flip-flopped, so it was only outputting white squares. Corrected for an additional 4 bytes saved. – AdmBorkBork – 2016-02-05T13:27:44.170

5

MATL, 11 (27) bytes

8:t!+Q2\TYG

This produces the following figure. It doesn't have an intrinsic size; it's automatically scaled depending on the size of the figure window. This seems to be allowed by the challenge.

enter image description here

Explanation

8:      % row vector [1,2,...8]
t!      % duplicate and transpose into column vector
+       % 8x8 matrix with all pairwise additions
Q       % add 1
2\      % modulo 2. Gives 8x8 matrix of zeros and ones
TYG     % draw image

If autoscaling is not allowed:

'imshow'8:t!+Q2\50t3$Y"0#X$

produces the following figure with 50x50-pixel squares

Explanation

enter image description here

'imshow'   % name of Matlab function
8:t!+Q2\   % same as above. Produces 8x8 matrix of zeros and ones
50t3$Y"    % repeat each element 50 times in each dimension
0#X$       % call imshow function with above matrix as input

Luis Mendo

Posted 2016-02-04T16:59:26.427

Reputation: 87 464

5

Pyth, 28 26 bytes

J*4+*50]255*50]0.wm_mxkdJJ

Explanation

J                          - Autoassign J = V
           *50]0           - 50*[0]
    *50]255                - 50*[255]
   +                       - ^^+^
 *4                        - 4*^
                .w         - write_greyscale(V)
                  m      J - [V for d in J]
                   _       - reversed(V) 
                    m   J  - [V for k in J]
                     xkd   - k^d

Python equivalent

J = 4*(50*[255]+50*[0])
write_greyscale([[k^d for k in J][::-1] for d in J])

Try it here (just the colour values)

Output:

Output

Blue

Posted 2016-02-04T16:59:26.427

Reputation: 26 661

Nice job on the byte count but I need a valid output with visible squares :) – Bruno – 2016-02-04T18:19:23.213

@Bruno Output added! I installed PIL just for you :O (I hadn't actually tested it before) – Blue – 2016-02-04T18:27:07.580

@muddyfish sorry for the trouble and thanks. The board must start with and end with a white square tho :) – Bruno – 2016-02-04T18:36:36.370

5

PHP + CSS + HTML, 136 bytes

Taking the table aproach to a higher level:

<table><?for(;++$i<9;)echo'<tr>',str_repeat(["<td b><td>","<td><td b>"][$i&1],4);?><style>td{width:50px;height:50px}[b]{background:#000}

It generates the following code:

<table><tr><td><td b><td><td b><td><td b><td><td b><tr><td b><td><td b><td><td b><td><td b><td><tr><td><td b><td><td b><td><td b><td><td b><tr><td b><td><td b><td><td b><td><td b><td><tr><td><td b><td><td b><td><td b><td><td b><tr><td b><td><td b><td><td b><td><td b><td><tr><td><td b><td><td b><td><td b><td><td b><tr><td b><td><td b><td><td b><td><td b><td><style>td{width:50px;height:50px}[b]{background:#000}

It relies heavily on browsers' kindness and CSS.

Ismael Miguel

Posted 2016-02-04T16:59:26.427

Reputation: 6 797

Good solution. Tho I had to include php after <? and include $i=0 as the first for parameter to get it working properly, giving a final result of 144 bytes. – Bruno – 2016-02-05T10:08:57.823

1

@Bruno If you refer to the warning it gives, warnings are disregarded here. However, there's a trillion ways of disabling them. One of them is to replace ++$i<9 with @++$i<9. Also, for it to work without <?php, one must have the directive short_open_tags=On, which is default on some environments. Read more on http://stackoverflow.com/a/2185331/2729937

– Ismael Miguel – 2016-02-05T10:26:33.457

5

Jelly, 26 bytes

400R%2ẋ€50FU;$ẋ4;;;1j⁶;”PU

Since Jelly has no support for images built in, we print a PPM image.

Try it online! (smaller board for speed, raw PPM)

Results

screenshot

How it works

400R%2ẋ€50FU;$ẋ4;;;1j⁶;”PU  Main link. No arguments.

400                         Set the left argument to 400.
   R                        Yield [1, ..., 400].
    %2                      Compute the parity of each integer.
      ẋ€50                  Replace each parity by an array of 50 copies of itself.
          F                 Flatten the resulting, nested list.
                            This creates the first rank of the board.
             $              Combine the two atoms to the left:
           U                  Reverse the array of parities.
            ;                 Concatenate the reversed array with the original.
                            This creates the first two ranks of the board.
              ẋ4            Repeat the resulting list four times.
                            This creates all eight ranks of the board.
                ;           Append 400, the link's left argument.
                 ;          Append 400, the link's left argument.
                  ;1        Append 1.
                    j⁶      Join, separating by spaces.
                      ;”P   Append the character 'P'.
                         U  Reverse the resulting list.

Non-competing version (24 bytes)

The newest Jelly interpreter that predates this post didn't vectorize x properly. With the latest version, 2 additional bytes can be saved.

400R%2x50U;$ẋ4;;;1j⁶;”PU

The only difference is that x50 yields a flat list (with every original element repeated 50 times), so F is no longer necessary.

Dennis

Posted 2016-02-04T16:59:26.427

Reputation: 196 637

1It looks like you were writing a java answer and fell asleep slightly whilst typing a ;... ;) – Conor O'Brien – 2016-02-04T23:31:51.080

1@CᴏɴᴏʀO'Bʀɪᴇɴ Java? You must be on Java 10.0, Golfing Edition, cause that doesn't look like any Java I've seen.... – BalinKingOfMoria Reinstate CMs – 2016-02-05T22:55:13.643

4

Matlab, 47 (24) bytes

imwrite(kron(mod(spiral(8),2),ones(50)),'.png')

This works exactly the same as my Octave answer, but I was able to use spiral which saved one byte. spiral(n) makes an nxn matrix and fills it spiraling with the first n^2 integers.

If vectorgraphics are allowed, we could do it in 24 bytes:

imshow(mod(spiral(8),2))

(This is the rescaled version, I do not want to clutter the answers here=)

flawr

Posted 2016-02-04T16:59:26.427

Reputation: 40 560

4

FFmpeg, 78 82 100 bytes

Finally got around to cleaning the board.

ffplay -f lavfi color=s=400x400,geq='255*mod(trunc(X/50)+trunc(Y/50)+1,2):128'

enter image description here


Older:

ffmpeg -f lavfi -i "color=tan@0:256x256,format=ya8" -vf "scale=400:-1:alphablend=checkerboard" .jpg

Will exit with error, but after producing image below.

enter image description here

(board's collected some dust)

Gyan

Posted 2016-02-04T16:59:26.427

Reputation: 521

3

CJam, 27 bytes

"P1"400__,2f%50e*_W%+4*~]S*

Try it online! (smaller board for speed, raw PPM)

Results

screenshot

How it works

"P1"                        e# Push that string.
    400__                   e# Push three copies of 400.
         ,                  e# Turn the last one into [0 ... 399].
          2f%               e# Compute the parity of each integer.
             50e*           e# Repeat each parity 50 times.
                            e# This creates the first rank of the board.
                 _W%        e# Create a reversed copy of the resulting array.
                    +       e# Concatenate the original with the reversed array.
                            e# This creates the first two ranks of the board.
                     4*     e# Repeat the resulting array four times.
                            e# This creates all eight ranks of the board.
                       ~    e# Dump all of its items (the pixels) on the stack.
                        ]   e# Wrap the entire stack in an array.
                         S* e# Join that array, separating them by spaces.

Dennis

Posted 2016-02-04T16:59:26.427

Reputation: 196 637

3

HTML with utf-8 - 66b

<div style="font:100 50px/48px serif">▚▚▚▚<br>▚▚▚▚<br>▚▚▚▚<br>▚▚▚▚

▚ is short-direct utf for entity &# 9626 ;

Unicode Character 'QUADRANT UPPER LEFT AND LOWER RIGHT' (U+259A)

silly me, was looking for a 1 utf-8 char solution -would have been... 1b!

pikappa

Posted 2016-02-04T16:59:26.427

Reputation: 31

2Seems like fontsize is wrong. – Qwertiy – 2016-02-06T20:20:24.193

1You should use instead so that the top-left square is white like on a standard chessboard. Also, use <pre> instead of <div> so that you can use newlines instead of <br>. – Neil – 2016-07-17T10:14:59.210

Your bytecount appears to be wrong, it should be 98 bytes, as counts for 3 bytes using UTF-8 encoding. In the future, you can use this to check your UTF-8 Byte Count

– Taylor Scott – 2017-10-11T17:30:53.720

2

PHP >=5.4, 175 159 149 116 Bytes

<table><tr><? for(;@++$i<65;)echo'<td width=50 height=50 ',$i+@$m&1?:'bgcolor=0','>',$i%8<1?'<tr '.($m=@!$m).'>':'';

<table><tr><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><tr 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><tr ><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><tr 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><tr ><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><tr 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><tr ><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><tr 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><td width=50 height=50 bgcolor=0><td width=50 height=50 1><tr >

Notes

  • Shaved 16 bytes - Thanks @insertusernamehere
  • Shaved 10 bytes - Thanks @msh210
  • Shaved 30 bytes - Thanks @Ismael Miguel

Shaun H

Posted 2016-02-04T16:59:26.427

Reputation: 732

1Probably this can be golfed even more, but here you go (152 bytes): <table><tr><?php for(;++$i<65;){echo'<td style="width:50px;height:50px;background:#'.(($i+$m)%2?'000':'').'"></td>';if($i%8<1){echo"</tr><tr>";$m=!$m;}} – insertusernamehere – 2016-02-04T20:03:13.813

While i didn't remove the initial assignments(Works, personal quirk won't let me do it), Thank for this – Shaun H – 2016-02-04T21:20:27.443

1

According to even the strict version of HTML 4, you can skip the end tag for TR.

– msh210 – 2016-02-05T00:07:00.610

Ok that was beautiful :) – Bruno – 2016-02-05T09:58:20.193

thanks @msh210, same goes for TD didn't even think about that – Shaun H – 2016-02-05T16:07:20.537

1Replace ++$i<65 with @++$i<65, since you are worried about the warnings. This means that you can reduce $m=$i=0 to just $m=0, saving you 2 bytes. Instead of echo 'a'.'b'.'c';, you can do echo 'a','b','c';. This means that your echo can be echo'<td style="width:50px;height:50px;background:#',($i+$m)%2?'':'000','">'; saving you more 2 bytes. Also, HTML attributes don't require quotes. Remove them and sabe 2 bytes. Also, there's a much shorter bgcolor attribute, that reduces more bytes! You can use a print() in the for to save even more bytes! – Ismael Miguel – 2016-02-06T11:53:03.180

1To save even more, I've replaced ($i+$m)%2 with $i+@$m&1, which allowed me to remove that $m=0. Ahead, I've been able to remove your if, and replaced it with a trenary operation. To save even more, I've removed your style and added the properties width and height. To get even more into the hacky side, I've figured that Chrome 48.0.2564.103 m uses black if the background color is 0, using the property bgcolor. That allowed me to ever reduce more! More reductions is better! – Ismael Miguel – 2016-02-06T12:14:25.920

The code: <table><tr><?php for(;@++$i<65;)echo'<td width=50 height=50 bgcolor=',$i+@$m&1?'':0,'>',$i%8<1?'<tr '.($m=@!$m).'>':''; - 119 bytes, effectivelly killing my own answer! Try it on http://sandbox.onlinephpfunctions.com/code/afd12390d40f03606befdcd77a61adfc006d7310 and test the output on https://jsfiddle.net/sgtuo1au/

– Ismael Miguel – 2016-02-06T12:16:53.910

2

PHP, 166 158 155 bytes

Works in PHP 7.0.2 (short-tags enabled) and Chrome 48.0.2564.97 m

<table><tr><? while(++$i<=8){while(++$j<=8){echo"<td style=background-color:".($i%2==0?($j%2==1?0:""):($j%2==0?0:"")).";padding:9></td>";}echo"<tr>";$j=0;}

MonkeyZeus

Posted 2016-02-04T16:59:26.427

Reputation: 461

You can use the property bgcolor=0 to generate the black background. That should shave off a ton of bytes! And instead of $v%2==0, use $v&1, which should shave a few bytes. – Ismael Miguel – 2016-02-06T12:19:11.457

1

Excel VBA, 82 Bytes

Anonymous VBE immediate window function that takes no input and outputs a checkerboard to the range A1:H8 on the ActiveSheet object

Cells.RowHeight=48:[B1:B8,D1:D8,F1:F8,H1:H8].Interior.Color=0:[A2,A4,A6,A8].Delete

This function works by first creating 4 black columns in the range B1:B8,D1:D8,F1:F8,H1:H8 and then offsetting the coloring in rows 2,4,6 and 8 to the left by one cell.

Sample Output

CheckerBoard

Taylor Scott

Posted 2016-02-04T16:59:26.427

Reputation: 6 709

1

JavaScript, 150

This can definitely be golfed. It creates HTML.

for(i=0;i<8;)console.log(`<b style=margin-${['lef','righ'][i++%2]}t:50;width:50;height:50;display:inline-block;background:#000></b>`.repeat(4)+'<br>')

Not that Charles

Posted 2016-02-04T16:59:26.427

Reputation: 1 905

1Huh, I never knew about template strings in JavaScript. Cool. – Cheezey – 2016-02-05T01:04:47.893

1

iKe, 24 bytes

,(;cga;t=\:t:2!-20!!160)

board

The core of the technique is to generate a list of x coordinates, divmod them and then take an equality cross-product to generate an appropriate bitmap. Using smaller examples for illustrative purposes:

  !8
0 1 2 3 4 5 6 7

  -2!!8
0 0 1 1 2 2 3 3

  2!-2!!8
0 0 1 1 0 0 1 1

  t=\:t:2!-2!!8
(1 1 0 0 1 1 0 0
 1 1 0 0 1 1 0 0
 0 0 1 1 0 0 1 1
 0 0 1 1 0 0 1 1
 1 1 0 0 1 1 0 0
 1 1 0 0 1 1 0 0
 0 0 1 1 0 0 1 1
 0 0 1 1 0 0 1 1)

try it here. Technically iKe works on a logical 160x160 pixel canvas, but in full-screen mode (the default when following a saved link) this is upscaled by 3x. I think this is still following the spirit of the question, as the program could assemble a much larger bitmap with the same character count; it just comes down to an arbitrary display limitation.

Update:

iKe isn't primarily designed for golf, but livecoding still benefits from brevity and sane defaults. As a result of tinkering with this problem, I've decided to permit it to use a default palette if none is provided. This particular solution could now be expressed with:

,(;;t=\:t:2!-20!!160)

Saving (an ineligible) 3 bytes.

JohnE

Posted 2016-02-04T16:59:26.427

Reputation: 4 632

1

Ruby with Shoes, 97 characters

Shoes.app(width:400){64.times{|i|stack(width:50,height:50){background [white,black][(i/8+i)%2]}}}

Sample output:

Chessboard drawn by Ruby with Shoes

manatwork

Posted 2016-02-04T16:59:26.427

Reputation: 17 865

Should start and end with white. Otherwise good job :) – Bruno – 2016-02-05T14:35:59.883

Oops. Thanks @Bruno. Fixed. – manatwork – 2016-02-05T16:48:45.520

Great, upvoted :) – Bruno – 2016-02-05T16:49:23.670

1

Lua + LÖVE, 138 113 112 106 characters

function love.draw()for i=0,31 do
love.graphics.rectangle("fill",i%8*50,(i-i%8)/8*100+i%2*50,50,50)end
end

Sample output:

Chessboard drawn by Lua + LÖVE

manatwork

Posted 2016-02-04T16:59:26.427

Reputation: 17 865

Grr! Lua 5.3 has // integer division operator, but apparently there is still no LÖVE built with a LuaJIT featuring it. ☹ – manatwork – 2016-02-05T16:53:25.317

1

J, 3331 bytes

I used a trick with binary.

   load'viewmat'
   viewmat 8 8$#:43605

... because 43605 in binary is 1010101001010101 (we use #: primitive to get it). Primitive $ shapes this array of binary digits into a matrix specified with the dimensions 8 8. And viewmat is just a system library.
enter image description here
The window is fully resizable.

Thanks to @FrownyFrog for shortening it to:

   load'viewmat'
   viewmat#:8$170 85

Dan Oak

Posted 2016-02-04T16:59:26.427

Reputation: 263

viewmat 8$#:170 85 is 1 byte shorter – FrownyFrog – 2017-10-09T10:04:08.777

1viewmat#:8$170 85 – FrownyFrog – 2017-10-09T10:23:14.770

1

GIMP, 539 bytes

gimp -i -b '(let* ((i (car (gimp-image-new 400 400 1))) (d (car (gimp-layer-new i 400 400 2 "b" 100 0)))) (gimp-image-insert-layer i d 0 -1) (define (t x y) (gimp-selection-translate i x y)) (define (x) (t 100 0)) (define (X) (t -100 0)) (define (y) (t 50 50)) (define (Y) (t -50 50)) (define (f) (gimp-edit-fill d 1)) (define (r) (f) (x) (f) (x) (f) (x) (f) (y)) (define (R) (f) (X) (f) (X) (f) (X) (f) (Y)) (gimp-image-select-rectangle i 2 0 0 50 50) (r) (R) (r) (R) (r) (R) (r) (R) (gimp-file-save 1 i d "c.png" "c.png") (gimp-quit 0))'

Ungolfed Scheme script-fu:

(let* ((i (car (gimp-image-new 400 400 GRAY)))
       (d (car (gimp-layer-new i 400 400 GRAY-IMAGE "b" 100 NORMAL-MODE))))

  (gimp-image-insert-layer i d 0 -1)
  (define (t x y) (gimp-selection-translate i x y))
  (define (x) (t 100 0))
  (define (X) (t -100 0))
  (define (y) (t 50 50))
  (define (Y) (t -50 50))
  (define (f) (gimp-edit-fill d BACKGROUND-FILL))
  (define (r) (f) (x) (f) (x) (f) (x) (f) (y))
  (define (R) (f) (X) (f) (X) (f) (X) (f) (Y))

  (gimp-image-select-rectangle i CHANNEL-OP-REPLACE 0 0 50 50)
  (r) (R) (r) (R) (r) (R) (r) (R)
  (gimp-file-save RUN-NONINTERACTIVE i d "c.png" "c.png")
  (gimp-quit 0))

In batch mode, create a blank image, create a 50x50 rectangular selection, fill it, and then repeatedly move it around the image, filling in squares. Then save to c.png and exit.

Output:

chessboard png

David Conrad

Posted 2016-02-04T16:59:26.427

Reputation: 1 037

0

Mathematica 43 bytes

ArrayPlot@Partition[Range[0,7]~Mod~2,8,1,1]
ArrayPlot@ArrayPad[{{0,1},{1,0}},3,"Periodic"]

matrix89

Posted 2016-02-04T16:59:26.427

Reputation: 623

It appears that this is two separate solutions - you should consider separating them and labeling the larger of the two as an alternate solution. Also, as this is a graphic challenge, including a screencap of the output really helps to make your solution stand out (and thus get more points :)) – Taylor Scott – 2017-10-12T02:19:07.180

0

LibreLogo, 121 bytes

LibreLogo produces a vector graphic that can be exported to SVG.

Code:

x=90 pu fc 0 repeat 64[ y=repcount if y%2=0[ square 1 ]if y%16=0[ rt x fd 1 rt x ][ if y%8=0[ lt x fd 1 lt x ][ fd 1 ] ]]

Result:

enter image description here

Result (Expanded):

enter image description here

Explanation:

x = 90                        ; x                  = 90°
pu                            ; Pen Up
fc 0                          ; Fill Color         = #000
repeat 64 [                   ; Repeat 64 Times
    y = repcount              ; y                  = Loop Index
    if y % 2 = 0 [
        square 1              ; Draw 1pt Square
    ]
    if y % 16 = 0 [
        rt x                  ; Turn Right 90°
        fd 1                  ; Move Forward 1pt
        rt x                  ; Turn Right 90°
    ] [
        if y % 8 = 0 [
            lt x              ; Turn Left 90°
            fd 1              ; Move Forward 1pt
            lt x              ; Turn Left 90°
        ] [
            fd 1              ; Move Forward 1pt
        ]
    ]
]

Grant Miller

Posted 2016-02-04T16:59:26.427

Reputation: 706

0

Tcl/Tk, 130 bytes

time {incr j
time {grid [text .t[incr i]_$j -bg [expr ([incr n]+$j)%2?"#000":"#FFF"] -wi 6 -he 3] -row $j -column $i} 8
set i 0} 8

Could not get exactly 50 pixels per square, so I went to a round-up! enter image description here

sergiol

Posted 2016-02-04T16:59:26.427

Reputation: 3 055

0

Haskell, 95 bytes

f s="Be7#"*>s<*[1..50]
main=mapM putStrLn$"P1\n400 400":f(concat.f<$>[["0 ","1 "],["1 ","0 "]])

Outputs to stdout a portable bitmap (PBM), shown below at half size.

enter image description here

Try it online!

Angs

Posted 2016-02-04T16:59:26.427

Reputation: 4 825

0

SELECT., 8844 8278 bytes

(9,9,50)EXP.SELECT.EXP.RIGHT.SELECT.LEFT.EXP.RIGHT.SELECT.LEFT.EXP.RIGHT.SELECT.LEFT.EXP.RIGHT.SELECT.LEFT.EXP.RIGHT.SELECT.LEFT.EXP.RIGHT.SELECT.LEFT.EXP.RIGHT.SELECT.LEFT.LOG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T.LEFT.LEFT.LEFT.LEFT.LEFT.LEFT.LEFT.LEFT.LEFT.LEFT.LEFT.LEFT.SELECT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.RIGHT.LOG.RIGHT.SELECT.EXP.LEFT.LEFT.SELECT.RIGHT.RIGHT.EXP.LEFT.SELECT.RIGHT.LOG.RIGHT.SELECT.LEFT.END.

Sure it's long, but the first two versions I generated for this task were twice as long.

Output:

screenshot

How it Works:

Here's the program used to generate it:

init(9,9,50)
makenum(8)
square()
dec()
loop("main",computei=True)
go(1)
makenum(8)
go(1)
copyfrom(-2)
intdiv(-1)
add(-5)           # n%8 blah blah blah blah n//8 k^(n//8) k^(n%8) (n//8+n%8)
go(1)
makeneg1()
exptarget(-1)
go(1)
ifnonpositive("drawtest")
go(1)
makenum(-4,-4)    # n%8 blah blah blah blah n//8 k^(n//8) k^(n%8) n//8+n%8 (-1)^(n//8+n%8) 4 1/2 I k^(-4I) -1 (-4-4I)
go(1)
multiply(-4,-11)   # n%8 blah blah blah blah n//8 k^(n//8) k^(n%8) n//8+n%8 (-1)^(n//8+n%8) 4 1/2 I k^(-4I) -1 -4-4I (nI//8)
add(-16)          # n%8 blah blah blah blah n//8 k^(n//8) k^(n%8) n//8+n%8 (-1)^(n//8+n%8) 4 1/2 I k^(-4I) -1 -4-4I nI//8 k^(nI//8) k^(n%8) (n%8+nI//8)
add(-4)           # n%8 blah blah blah blah n//8 (-1)^(n%8) 4 1/2 I k^(-4I) -1 -4-4I nI//8 k^(nI//8) k^(n%8) n%8+nI//8 k^(n%8+nI//8) k^(-4-4I) ((n%8-4)+I(n//8-4))
output()
endif("drawtest")
go(1)
endloop("main")
writetofile("chessboard4")

In other words, loop n from 0 to 63, drawing a square at (n%8-4) + (n//8-4)i if (-1)^(n//8 + n%8) is not positive.

quintopia

Posted 2016-02-04T16:59:26.427

Reputation: 3 899

Thats not really golf is it :p? – Bruno – 2016-02-05T15:04:51.743

I cannot be certain it's the shortest program that does the task, no. However, I am fairly certain that the difference between this and the best possible solution in this language is insignificant compared to the total length of the program. I have one more idea in mind that may or may not be shorter. I'll try it out sometime soon. – quintopia – 2016-02-05T17:38:36.190

0

Perl 5 - 80

Generates a .PBM file:

print 'P1'.' 400'x2 .$".(((0 x50 .1 x50)x4 .$")x50 .((1 x50 .0 x50)x4 .$")x50)x4

ChatterOne

Posted 2016-02-04T16:59:26.427

Reputation: 171

0

PowerShell + GDI, 346 bytes

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$f=New-Object Windows.Forms.Form
$f.width=$f.height=450
$g=$f.CreateGraphics()
$f.add_paint({0..7|%{$y=$_;0..7|%{$g.FillRectangle((New-Object Drawing.SolidBrush ("white","black")[($_+$y)%2]),(new-object Drawing.Rectangle ($_*50),($y*50),50,50))}}})
$f.showDialog()

(newlines count same as semicolon, so newlines for readability)

As opposed to my other answer, this one uses the .NET assemblies to call GDI+ function calls. Interestingly, it's about twice the length.

The first two lines load the System.Windows.Forms and System.Drawing assemblies. The first is used for the literal window and the canvas thereon, the second is used for the drawing object (in this code, a brush) that create the graphics on the canvas.

We then create our form $f with the next line, and set its width and height to be 450. Note that this isn't 50*8, since these numbers correspond to the border-to-border edge of the forms window, including titlebar, the close button, etc.

The next line creates our canvas $g by calling the empty constructor. This defaults to the upper-left of the non-system area of the form being equal to 0,0 and increasing to the right and downward, perfect for our needs.

The next line is the actual call that draws the graphics, with $f.add_paint({...}). We construct the graphics calls by double-for looping from 0..7 and carrying a helper variable $y through each outer loop. Each inner loop, we tell our canvas to .FillRectangle(...,...) to draw our squares. The first parameter constructs a new SolidBrush with a color based on where we're at on the board. Other options here could be a hatch, a gradient, etc. The second parameter is a new Rectangle object starting at the specified x $_*50 and $y*50 coordinates and extending for 50 in each direction. Remember that 0,0 is the top-left.

The final line just displays the output with .showDialog(). PowerShell Forms

Note that since we're creating a form object, and PowerShell is all about the pipeline, closing the pop-up form will pass along a System.Enum.DialogResult object of Cancel, since that's technically what the user did. Since we're not capturing or otherwise doing anything with that result, the word Cancel will be displayed to STDOUT when the program concludes, as it was left on the pipeline.

AdmBorkBork

Posted 2016-02-04T16:59:26.427

Reputation: 41 581

0

JavaScript (ES6), 147

for(i=0;++i<72;)document.write(`<div style="${i%9?'':(++i,'clear:both;')}float:left;width:50px;height:50px;background:#${i&1?'fff':'000'}"></div>`)

edc65

Posted 2016-02-04T16:59:26.427

Reputation: 31 086

0

Python, 57 bytes

c=50*"1"+50*"0"
print"P1 400 400 "+4*(200*c+200*c[::-1])

c is a line of 50 white and 50 black pixels, 200*c is a row with a white in the front, 200*c[::-1] the reverse.

Output as PPM, usage:

python golf_chess.py > chess.ppm

Karl Napf

Posted 2016-02-04T16:59:26.427

Reputation: 4 131

0

C, 157 Bytes

#include <stdio.h>
x,q,a;FILE*f;w(){f=fopen("a","w");fprintf(f,"P1400 400 ");for(;a++<8;)for(q=0;q++<400;)for(x=0;x++<50;)fprintf(f,"%d",(q+a)%2);fclose(f);}

This generate the file a, one PBM file.
You should add the .pmb extension

Full Program

#include <stdio.h>
x,q,a;FILE*f;w(){f=fopen("a","w");fprintf(f,"P1400 400 ");for(;a++<8;)for(q=0;q++<400;)for(x=0;x++<50;)fprintf(f,"%d",(q+a)%2);fclose(f);}
main(){w();}

C, Shorter Version (98 Bytes)

x,q,a;w(){printf("P1400 400 ");for(;a++<8;)for(q=0;q++<400;)for(x=0;x++<50;)printf("%d",(q+a)%2);}  

This version print in the STDOUT the file. So you have to redirect it in the file manually.

Giacomo Garabello

Posted 2016-02-04T16:59:26.427

Reputation: 1 419

Should one not add a .pbm extension rather than .pmb? – Jonathan Frech – 2017-10-08T01:25:19.337

I think your 98 bytes long approach defines a function that is not reusable. – Jonathan Frech – 2017-10-08T01:26:51.727