/oRe./'+Ao
\I*tI&0-R$@/
在线尝试!
输入应以换行分隔,第一行的数字和第二行的宽度。
说明
/...
\...@/
这是Ordinal模式下线性程序的常用框架。在这种情况下,唯一的问题是此位:
.../...
...&...
这将导致IP垂直进入Cardinal模式并仅&
在Cardinal模式下执行,然后才能恢复为Ordinal模式。
展开之字形控制流程然后给出:
IRt.&'-A$o*eI/&/0+Ro@
I Read the first line of input (the value) as a string.
R Reverse the string.
t. Split off the last character and duplicate it.
& Fold the next command over this string. This doesn't really do anything,
because the string contains only one character (so folding the next
command is identical to executing it normally).
'- Push "-".
A Set intersection. Gives "-" for negative inputs and "" otherwise.
$o If it's "-", print it, otherwise it must have been a digit which we
leave on the stack.
* Join the digit back onto the number. If the number was negative, this
joins the (absolute value of the) number to an implicit empty string,
doing nothing.
e Push an empty string.
I Read the width W.
/&/ Iterate the next command W times.
0 Append a zero. So we get a string of W zeros on top of the absolute
value of the input number.
+ Superimpose. This takes the character-wise maximum of both strings
and appends extraneous characters from the longer string. Since the
string of zeros can never be larger than the digits in the input,
the input itself will be uneffected, but extraneous zeros are appended,
padding the string to the required length.
R Reverse the result.
o Print it.
@ Terminate the program.
这是两个备选方案,也是23个字节,它们使用Cardinal H
(abs)摆脱了-
:
/R.I&0-RoH
\Ie#\'+Ao\@/
/R.H#/.+Xo
\Ie\I&0QRo@/
原则上来说,这些命令要短一些,但是&
不适合放在堆栈上有1个字符的字符串的位置,因此我们需要使用来跳过它#
。