Alice , 23 Bytes
/oRe./'+Ao
\I*tI&0-R$@/
Probieren Sie es online!
Die Eingabe sollte mit der Nummer in der ersten Zeile und der Breite in der zweiten Zeile durch einen Zeilenvorschub getrennt sein.
Erläuterung
/...
\...@/
Dies ist der übliche Rahmen für lineare Programme im Ordinalmodus. Der einzige Haken in diesem Fall ist dieses Bit:
.../...
...&...
Dies bewirkt, dass die IP vertikal in den Kardinalmodus wechselt und nur den Befehl ausführt & Kardinalmodus bevor sie wieder in den Ordinalmodus wechselt.
Das Entfalten des Zickzack-Kontrollflusses ergibt dann:
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.
Hier sind zwei Alternativen, ebenfalls bei 23 Bytes, die Cardinal H( abs ) verwenden, um das loszuwerden -:
/R.I&0-RoH
\Ie#\'+Ao\@/
/R.H#/.+Xo
\Ie\I&0QRo@/
Im Prinzip sind diese Befehle kürzer, aber &sie passen nicht in eine Position, in der sich eine 1-Zeichen-Zeichenfolge auf dem Stapel befindet. Wir müssen sie daher mit einem überspringen #.