TransWikia.com

Shortest way to make a checkerboard pattern

Mathematica Asked on February 20, 2021

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

2 Answers

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

Answered by boomboom on February 20, 2021

28 characters:

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

enter image description here

12 key strokes:

=chess board

enter image description here

Answered by kglr on February 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP