MATL,46 42 34字节
12tEt:qy/t15XObZ"!b16XOhhkw14:X~Z)
以前是42字节12tEt:q2M/736330+t15XObZ"!b16XOhhkw14:X~Z)
和46字节736330 24t:qw/+t15XO' '24TX"b16XOhhk14: 12X~Z)
。当然不需要736330,那太疯狂了!
注意:不适用于TryItOnline,我认为Matlab和的Octaves实现之间存在兼容性问题datestr
。
datestr
以日期的数字表示形式并将其转换为该日期的字符串表示形式。一天中的时间是数字的小数部分,因此0.0对应于时间00:00:00的一月0,0000,而1.0对应于00:00:00的0000年1月1日。1/24是1 am、2/24 2am等。
说明
12t % push a 12 onto the stack and duplicate
Et % double the 12 and duplicate the 24 (stack now has 12, 24, 24, bottom to top)
:q % make vector 1:24 and decrement by 1, stack has 12, 24, 0:23
y % duplicate second element on stack (24)
/ % divide, for (0:23)/24
t % duplicate elements
15XO % string representation of date, 15 specifies format
b % bubble up element in stack (gets a 24 on top of the stack)
Z"! % makes a column of 24 spaces, to put between columns of times
b % bubble up another (0:23)/24
16XO % string representation of date, 16 for a different format
hh % concatenate two time vectors and the column of spaces
k % convert string to lowercase, because CO gives AM/PM not am/pm
w % swap elements in stack, that first 12 is now on top
14: % vector of equally spaced values 1:14
X~ % set exclusive-or, returns [1 2 3 4 5 6 7 8 9 10 11 13 14]
Z) % get the right columns of the string array to remove extra column of blanks
% implicit display
为了显示它在Matlab中的工作原理,这是一个屏幕截图