Skip to main content
Tweeted twitter.com/StackCodeGolf/status/1454961431439417345
Became Hot Network Question
deleted 10 characters in body
Source Link
Bubbler
  • 78.4k
  • 5
  • 149
  • 469
  1. Create a checkerboard of 0s and 1s of the given size, the 0corners being at the corner0.
  2. If \$b > 0\$, overwrite the checkerboard with 2s in the X shape at the center, each leg being of length \$b\$ (not counting the center).
  1. Create a checkerboard of 0s and 1s of the given size, the 0 being at the corner.
  2. If \$b > 0\$, overwrite the checkerboard with 2s in the X shape at the center, each leg being of length \$b\$ (not counting the center).
  1. Create a checkerboard of 0s and 1s of the given size, corners being 0.
  2. If \$b > 0\$, overwrite the checkerboard with 2s in the X shape at the center, each leg being of length \$b\$ (not counting the center).
Source Link
Bubbler
  • 78.4k
  • 5
  • 149
  • 469

Checkered grid with X mark

Challenge

Given two integer values \$a \ge 2\$ and \$0 \le b < a\$, generate a \$(2a-1) \times (2a-1)\$ matrix consisting of the integers 0, 1, and 2 as follows:

  1. Create a checkerboard of 0s and 1s of the given size, the 0 being at the corner.
  2. If \$b > 0\$, overwrite the checkerboard with 2s in the X shape at the center, each leg being of length \$b\$ (not counting the center).

This pattern is directly modeled from Art Puzzle event grids (where \$a\$ is fixed at 3, \$b=0,1,2\$ represent easy/normal/hard grids, and the 0, 1, 2s in the output represent easy/normal/hard minipuzzles respectively). Blame it if you don't like the edge case of \$b=0\$ :P

Standard rules apply. The shortest code in bytes wins.

Test cases

a = 2, b = 0
[[0, 1, 0],
 [1, 0, 1],
 [0, 1, 0]]

a = 2, b = 1
[[2, 1, 2],
 [1, 2, 1],
 [2, 1, 2]]

a = 3, b = 0
[[0, 1, 0, 1, 0],
 [1, 0, 1, 0, 1],
 [0, 1, 0, 1, 0],
 [1, 0, 1, 0, 1],
 [0, 1, 0, 1, 0]]

a = 3, b = 1
[[0, 1, 0, 1, 0],
 [1, 2, 1, 2, 1],
 [0, 1, 2, 1, 0],
 [1, 2, 1, 2, 1],
 [0, 1, 0, 1, 0]]

a = 3, b = 2
[[2, 1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