MATL , 28 바이트
c!t&n:q3_*ts_b+5M4$XdZ!cZ{Zv
입력은 문자열의 셀형 배열이며 쉼표는 선택적 구분 기호로 사용됩니다.
{'programming' 'puzzles' 'and' 'code' 'golf'}
또는
{'programming', 'puzzles', 'and', 'code', 'golf'}
온라인으로 사용해보십시오! 또는 모든 테스트 사례를 확인하십시오 : 1 , 2 , 3 , 4 .
설명
예를 들어 다음 입력을 고려하십시오.
{'aaaa' 'bb' 'ccc'}
%
코드의 어느 지점에서나 주석 기호 를 삽입하는 부분 결과 (스택 내용)를 볼 수 있습니다 . 예를 들어 네 번째 함수 ( ) 다음에 스택 내용 을 봅니다&n
.
c % Input cell array of strings implicitly. Convert to 2D char array,
% right-padding with spaces
% STACK: ['aaaa'; 'bb '; 'ccc']
! % Transpose
% STACK: ['abc'
'abc'
'a c'
'a ']
t % Duplicate
% STACK: ['abc'
'abc'
'a c'
'a '],
['abc'
'abc'
'a c'
'a '],
&n % Number of rows and of columns
% STACK: ['abc'
'abc'
'a c'
'a '], 4, 3
:q % Range, subtract 1
% STACK: ['abc'
'abc'
'a c'
'a '], 4, [0 1 2]
3_* % Multiply by -3
% STACK: ['abc'
'abc'
'a c'
'a '], 4, [0 -3 -6]
ts_ % Duplicate, sum, negate
% STACK: ['abc'
'abc'
'a c'
'a '], 4, [0 -3 -6], 9
b % Bubble up in stack
% STACK: ['abc'
'abc'
'a c'
'a '], [0 -3 -6], 9, 4
+ % Add
% STACK: ['abc'
'abc'
'a c'
'a '], [0 -3 -6], 13
5M % Push second input of last function again
% STACK: ['abc'
'abc'
'a c'
'a '], [0 -3 -6], 13, 4
4$Xd % Buld numerical sparse matrix from the above four arguments. The
% columns of the first input argument will be the diagonals of the
% result, with indices given bu the second input (negative is below
% main diagonal). The matrix size is the third and fourth arguments
% STACK: [97 0 0 0
0 97 0 0
0 0 97 0
98 0 0 97
0 98 0 0
0 0 32 0
99 0 0 32
0 99 0 0
0 0 99 0
0 0 0 32
0 0 0 0
0 0 0 0
0 0 0 0]
Z!c % Convert from sparse to full, and then to char. Character 0 is
% displayed as space
% STACK: ['a '
' a '
' a '
'b a'
' b '
' '
'c '
' c '
' c '
' '
' '
' '
' ']
Z{ % Split into cell array, with each row in a cell
% STACK: {'a ', ' a ', ' a ', 'b a', ' b ', ' ', 'c ', ' c ', ' c ', ' ', ' ', ' ', ' '}
Zv % Deblank: remove trailing space from each string. Implicitly display,
% each string on a different line. Empty strings do not generate
% a newline
% STACK: {'a ', ' a', ' a', 'b a', ' b', '', 'c', ' c', ' c', '', '', '', ''}