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$
4
  • $\begingroup$ Graphics@{"Checkerboard"~PatternFilling~ImageScaled[1/10],Rectangle[]} would shave off 1 character… $\endgroup$
    – SHuisman
    Commented Sep 29, 2020 at 19:58
  • $\begingroup$ 52 characters: Graphics@{PatternFilling@"Checkerboard",Rectangle[]} $\endgroup$
    – kglr
    Commented Sep 29, 2020 at 21:45
  • $\begingroup$ mathematica.stackexchange.com/q/206302/7339 and codegolf.stackexchange.com/q/71093/90804 $\endgroup$
    – expression
    Commented Sep 30, 2020 at 7:20
  • $\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$ Commented Oct 6, 2020 at 19:41

2 Answers 2

10
$\begingroup$

28 characters:

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

enter image description here

12 key strokes:

=chess board

enter image description here

$\endgroup$
3
9
$\begingroup$

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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