Write a program or function that takes in three positive integers, W, H, and N. Print or return a W×H grid of .
's where every Nth .
in normal English reading order is replaced with an X
.
For example, given W = 7, H = 3, N = 3, the grid is 7 characters wide and 3 high, and every third character reading from the top left is an X
:
..X..X.
.X..X..
X..X..X
Similarly, if the input is W = 10, H = 4, N = 5, the output would be:
....X....X
....X....X
....X....X
....X....X
Notes
- "Normal English reading order" means going left to right on each line, from the top line to the bottom.
- When N is 1 then all the
.
's will becomeX
's. - You may use any two distinct printable ASCII characters in place of
.
andX
.- If you use space (
- You may not using something else in place of the newlines that shape the grid.
- If you use space (
- The exact input format and order of W, H, and N is not super important. Things like
[H,W,N]
orN\nW,H
are alright. - A trailing newline in the output is fine.
- The shortest code in bytes wins!
Examples
W = 5, H = 3, N = 1
XXXXX
XXXXX
XXXXX
W = 5, H = 3, N = 2
.X.X.
X.X.X
.X.X.
W = 5, H = 3, N = 3
..X..
X..X.
.X..X
W = 5, H = 3, N = 4
...X.
..X..
.X...
W = 5, H = 3, N = 5
....X
....X
....X
W = 5, H = 3, N = 6
.....
X....
.X...
W = 5, H = 3, N = 7
.....
.X...
...X.
W = 5, H = 3, N = 15
.....
.....
....X
W = 5, H = 3, N = 16 (or more)
.....
.....
.....
W = 1, H = 1, N = 1
X
W = 1, H = 1, N = 2 (or more)
.
W = 8, H = 6, N = 2
.X.X.X.X
.X.X.X.X
.X.X.X.X
.X.X.X.X
.X.X.X.X
.X.X.X.X
W = 8, H = 6, N = 3
..X..X..
X..X..X.
.X..X..X
..X..X..
X..X..X.
.X..X..X
W = 8, H = 6, N = 4
...X...X
...X...X
...X...X
...X...X
...X...X
...X...X
W = 8, H = 6, N = 7
......X.
.....X..
....X...
...X....
..X.....
.X......
W = 8, H = 6, N = 16
........
.......X
........
.......X
........
.......X
W = 37, H = 1, N = 4
...X...X...X...X...X...X...X...X...X.
W = 1, H = 10, N = 8
.
.
.
.
.
.
.
X
.
.
["..X..X.", ".X..X..", "X..X..X"]
as the grid"? \$\endgroup\$