We all know run-length decoding: A list of character-length pairs expands to a string of that many characters, so A1B4C2
expands to ABBBBCC
. But what if we stretch this concept to 2 dimensions?
Instead of character-length pairs, in this challenge you will be given character-length-direction triples. For example, using N/S/E/W to indicate direction, the input A4E B5S C3W D3N E1W
should yield the output
AAAAB
B
E B
D B
D B
DCCC
You can take input in any reasonable format (such as a list of (char, length, N/E/S/W)
like shown here, or perhaps (0/1/2/3, length, char)
).
The input will not overlap itself, so A5E B3W
or A5E B4S C4W D4N
is invalid input.
The input will also not expand past the left or top edges of the string, only the bottom and right edges will be expanded.
The character will always be within the printable ASCII range.
Consistent trailing or leading whitespace that does not affect the presentation of the output is fine.
This is code-golf, so the shortest submission per language, measured in bytes, wins.
Here are a couple cases to test your entry against:
A4E B5S C3W D3N E1W
AAAAB
B
E B
D B
D B
DCCC
A4E B5S C3W D3N -2E -1N 2W |1S
AAAAB
| B
---B
D B
D B
DCCC
.3S 2E ,3N 2E .5S
. .
. , .
. , .
, .
.
>6E v3S <6W ^2N >5E v1S <5W
>>>>>>v
>>>>>vv
^<<<<<v
^<<<<<<