:"ct32>*TTYatFTEqYSy~*+c
入力形式は
2
{'X X DD', ' X D D', 'X X DD'}
他の例は
1
{'###', '###'}
出力には、チャレンジで許可されている余分な空白が含まれています。
オンラインでお試しください!
2D char配列が入力として受け入れられる場合(私はOPを2回尋ねました...)、最初の配列をc削除できるため、23バイトです:
:"t32>*TTYatFTEqYSy~*+c
この場合の入力形式は次のとおりです(すべての文字列の長さは等しいため、スペースで右詰めする必要があります)。
2
['X X DD '; ' X D D'; 'X X DD ']
オンラインでお試しください!
説明
: % Input number n implicitly. Generate [1 2 ... n]
" % For loop: repeat n times
c % Convert to char array. In the first iteration it inputs a cell array of
% strings implicitly and converts to a 2D char array, right-padding with
% spaces. In the next iterations it does nothing, as the top of the stack
% is already a 2D char array
t32>* % Convert characters below 32 into 0
TT % Push array [1 1]
Ya % Pad the 2D char array with one zero in the two directions (up/down,
% left/right), on both sides
t % Duplicate
FTEq % Push array [-1 1]
YS % Circularly shift the 2D char array one unit up and one unit right
y % Push a copy of the non-shifted 2D array
~ % Logical negate: nonzero entries become 0, zero entries become 1. This
% will be used as a mask for entries that need to be changed. Since the
% values at those entries are zero, we can simply add the new values. We do
% that by multiplying the mask by the shifted array and adding to the
% non-shifted array
* % Multiply element-wise
+ % Add element-wise
c % Convert the 2D array back to char
% End for
% Implicitly display