10
Given an input of a pair of nonnegative integers describing a leaper in chess, output a diagram of the squares to which the leaper can move.
From Wikipedia's description:
An (m,n)-leaper is a piece that moves by a fixed type of vector between its start square and its arrival square. One of the coordinates of the vector 'start square – arrival square' must have an absolute value equal to m and the other one an absolute value equal to n. [...] For instance, the knight is the (1,2)-leaper.
In normal-people-speak, an (m,n)-leaper can move m squares in any direction, turn 90 degrees, and move n more squares. For example, a (1,2)-leaper (also known as the knight) can move to these squares:
.E.E.
E...E
..S..
E...E
.E.E.
where S
represents the start square, E
represents the end square, and .
represents an empty square. This must also be your output for the input 1 2
(and 2 1
).
Specifically, the output must
be a square grid with side length
max(m,n) * 2 + 1
.contain exactly one
S
, located in the center of the square.contain
E
s at the positions that a (m,n)-leaper atS
could move to.contain dots (
.
) at all other positions.
You may assume that m ≥ 0
, n ≥ 0
, m + n > 0
, and that m
and n
are
integers.
Output may be a single string, an array of lines, or an array of arrays of characters.
Since this is code-golf, the shortest code in bytes will win.
Test cases (all test cases should work with input integers swapped as well):
4 1
...E.E...
.........
.........
E.......E
....S....
E.......E
.........
.........
...E.E...
2 2
E...E
.....
..S..
.....
E...E
3 0
...E...
.......
.......
E..S..E
.......
.......
...E...
1 1
E.E
.S.
E.E
0 1
.E.
ESE
.E.
12 13
.E.......................E.
E.........................E
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
.............S.............
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
E.........................E
.E.......................E.
I had a 145 byte answer but the question was closed before I could post it... – Neil – 2016-03-05T23:37:24.510