7
$\begingroup$

I'm looking for the shortest (in terms of characters) code snippet to make an n-square checkerboard. Here's my first try (comes in at 72 characters):

Graphics@{PatternFilling["Checkerboard", ImageScaled[1/10]], 
  Rectangle[]}

enter image description here

And my second try, which is a bit shorter (42 characters):

Image @ Table[.5 + (-1)^(i + j)/2, {i, 10}, {j, 10}]

enter image description here

$\endgroup$
  • $\begingroup$ Graphics@{"Checkerboard"~PatternFilling~ImageScaled[1/10],Rectangle[]} would shave off 1 character… $\endgroup$ – SHuisman Sep 29 at 19:58
  • $\begingroup$ 52 characters: Graphics@{PatternFilling@"Checkerboard",Rectangle[]} $\endgroup$ – kglr Sep 29 at 21:45
  • $\begingroup$ Mathematica ought to help us find the shortest code to do the job! After all, computer systems are supposed to do work for us, not the other way around. $\endgroup$ – Ralph Dratman Oct 6 at 19:41
10
$\begingroup$

28 characters:

Image@Array[(-1)^+## &, {8, 8}]

enter image description here

12 key strokes:

=chess board

enter image description here

| improve this answer | |
$\endgroup$
9
$\begingroup$

Try Image[Array[Mod[#+#2,2]&,{8,8}]]

| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ You can use @ rather than [...] to save 1 character $\endgroup$ – mikado Sep 29 at 20:01
  • 4
    $\begingroup$ .Image@Array[Mod[+##,2]&,{8,8}] saves two characters. $\endgroup$ – kglr Sep 29 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.