MathOverflow will be down for maintenance for approximately 3 hours, starting Monday evening (06/24/2013) at approximately 9:00 PM Eastern time (UTC-4).

2 added 1 characters in body

If you've ever written code to convert an integer into a string of decimal digits, you may have come to the conclusion that the integer 0 should map not to the string 0, but to the empty string instead. Most algorithms I've seen need to introduce a kludge to make 0 come out right. After all, when we write 0 we are violating the usual rule of "no leading zeros".

A nice, natural recursive expression of the conversion process is

def itoa(n):
if n==0: return ""
return itoa(n/10) + chr(ord('0') + n%10)


which can be thought of as
The string representation of an integer consists of its leading digits (n/10) followed by its last digit (n%d).n%10).

Trying to fix this by returning "0" instead of "" would result in everything getting a superfluous leading zero.

On the other hand writing 0 as the empty string would be rather annoying.

If you've ever written code to convert an integer into a string of decimal digits, you may have come to the conclusion that the integer 0 should map not to the string 0, but to the empty string instead. Most algorithms I've seen need to introduce a kludge to make 0 come out right. After all, when we write 0 we are violating the usual rule of "no leading zeros".

A nice, natural recursive expression of the conversion process is

def itoa(n):
if n==0: return ""
return itoa(n/10) + chr(ord('0') + n%10)


which can be thought of as
The string representation of an integer consists of its leading digits (n/10) followed by its last digit (n%d).

Trying to fix this by returning "0" instead of "" would result in everything getting a superfluous leading zero.

On the other hand writing 0 as the empty string would be rather annoying.