The challenge
Given two integers as input (x
and y
), output x
as a string with as many leading zeroes necessary for it to be y
characters long without the sign.
Rules
If
x
has more thany
digits, outputx
as string without modification.Output as integer is not accepted, even if there are no leading zeroes.
When
x
is negative, keep the-
as is and operate on the absolute value.Negative
y
should be treated as 0, meaning you outputx
as is (but as string)
Examples:
IN: (1,1) OUT: "1"
IN: (1,2) OUT: "01"
IN: (10,1) OUT: "10"
IN: (-7,3) OUT: "-007"
IN: (-1,1) OUT: "-1"
IN: (10,-1) OUT: "10"
IN: (0,0) OUT: "0"
IN: (0,1) OUT: "0"
IN: (0,4) OUT: "0000"
Shortest code in bytes wins, standard loopholes apply.
(-1,1)
give? \$\endgroup\$ – Adám Dec 1 '17 at 9:59+
sign acceptable for positive numbers? \$\endgroup\$ – Tom Carpenter Dec 1 '17 at 17:21