In a recent question for which the correct output for
1 is zero, an answer output
; i.e, nothing. Is this an acceptable base-10 representation for zero?
In a recent question for which the correct output for
No, besides exceptions.
The challenge linked obviously requires the output to be a number for valid inputs.
The empty string is not a number. The fact that empty strings evaluate to 0 in some languages doesn't justify its use as the number 0. Otherwise I could argue that
"a" is valid to represent
97 in outputs because it's the corresponding ASCII code.
The only case I can think of where outputting
"" for 0 is OK is when your output is in unary.
1\$\begingroup\$ While I don't necessarily disagree with your conclusion, saying that the empty string is not a number is simply false. Bijective numerations do not have a zero symbol, and an empty string is the only way to represent the number zero. \$\endgroup\$– DennisFeb 12, 2016 at 22:25
\$\begingroup\$ That's why I said that there can be exceptions, if there are no more natural ways of writing 0. In standard base 10 that's definately not the case. \$\endgroup\$ Feb 12, 2016 at 22:28
\$\begingroup\$ @Sp3000 Due to that policy (which I agree with), I only halfway agree with this answer.
ais a valid representation of 97, so
0x00(the null byte) would be an acceptable representation of 0. A null byte is not the same as an empty string, so an empty string would not be acceptable (unary notwithstanding). \$\endgroup\$– user45941Feb 15, 2016 at 0:41
The mathematical definition of a base-10 representation is:
Where an...a1a0 is the base-10 representation. The value of the empty string is well-defined as the empty sum, 0.
The empty string can be considered a more consistent representation than
0, since it follows the convention that numbers have no leading zeroes.
3\$\begingroup\$ The empty string is not a legitimate representation of
0. The number with no digits`` is a legitimate representation of 0 (This is actually how 0 was historically written(i.e. not written)). The empty string is a string that contains the empty number but is not itself a number. You can't input the empty string into your formula since it is composed of delimiters that are not digits. Finally, everyone has agreed for hundreds of years now that
0is a more convenient representation than the number with no digits. \$\endgroup\$ Feb 12, 2016 at 22:20
2\$\begingroup\$ I don't follow. How is the empty string different from the number with no digits? \$\endgroup\$ Feb 12, 2016 at 22:21
\$\begingroup\$ It's different just as
""is different from
. The string that contains the empty list is not itself a list. Similarly, a string that contains a number with no digits is not itself a number. \$\endgroup\$ Feb 12, 2016 at 22:24
2\$\begingroup\$ Don't we allow programs that output the number
3.14to output the string "3.14"? This doesn't seem different. \$\endgroup\$ Feb 12, 2016 at 22:27
\$\begingroup\$ It doesn't matter that you manipulate a string as long as the output is formatted as a number, namely
"3.14". If you language prints
0when you ask it to print the empty string then it's perfectly fine, since the final output is a number. But if it outputs
""when you ask to print
""then your output is not a number. \$\endgroup\$ Feb 12, 2016 at 22:30
\$\begingroup\$ You said earlier that the number with no digits is a number. How is "" (without quotes) not a number, but "3.14" a number? \$\endgroup\$ Feb 12, 2016 at 22:35
""without quotes, as you say, is a number, namely the number with no digits, which has now been for hundreds of years written
""without quotes is not
"", which is the empty string. Therefore an output of nothing (and not an output of
"") would be valid as the number 0, but I guess wouldn't be valid overall because then it's debatable that you would have outputed anything. \$\endgroup\$ Feb 12, 2016 at 22:56
1\$\begingroup\$ I don't feel like people are on the same page with all of the ""
"0". Which quotes are included in the output? For example, would
System.out.print("")qualify, since there aren't any quotes in the output? \$\endgroup\$– PhiNotPiFeb 12, 2016 at 23:10
\$\begingroup\$ To add to PhiNotPi: what about returning the empty string from a function, which is considered output, too. \$\endgroup\$– nimiFeb 12, 2016 at 23:46
\$\begingroup\$ @nimi That doesn't apply here; we allow programs to print the string
3.14for a number, because there's no way to print an integer. I don't think we allow functions to return the string
3.14for the number 3.14. \$\endgroup\$ Feb 12, 2016 at 23:48
\$\begingroup\$ @ThomasKwa: it does apply. Functions may output via return value. If the empty string is a valid representation for
0, then I'm allowed to return it from a function. \$\endgroup\$– nimiFeb 12, 2016 at 23:58
\$\begingroup\$ @PhiNotPi Yes, just like
System.out.print("3.14"). \$\endgroup\$ Feb 13, 2016 at 1:46
In both the mathematical base conversion algorithm:
def frombase(array,base): ret = 0 for digit in array: ret = ret * base + digit return ret
and in many languages interpretation (e.g.,
[int]""), the empty string evaluates to zero.
Thus, for a challenge requesting decimal output, an empty string is acceptable to output for zero.
1\$\begingroup\$ I would say that it should only count in languages where that is the case, personally. If your language does something different or throws an error, then it shouldn't be allowed. This would be in line with our general position on truthy/falsey: It needs to work as a conditional in the chosen language. \$\endgroup\$– GeobitsFeb 12, 2016 at 18:06
2\$\begingroup\$ @Geobits I was going to suggest the same thing, until I realized that it would not determine the validity of this particular answer. Jelly has no way to cast to
int. (That's a problem with the truthy/falsy definiton as well. What if the language doesn't have conditionals?) \$\endgroup\$– DennisFeb 12, 2016 at 18:10
\$\begingroup\$ I have mixed feelings. I'd like to say "no", but the empty string is the only way to output zero for unary output, which is allowed... \$\endgroup\$– mbomb007Feb 12, 2016 at 19:07
\$\begingroup\$ Here I see "" as an expression which evaluates to zero, which seems invalid for the same reason that any other expression is, like outputting "1-1", when a number was required. \$\endgroup\$ May 27, 2016 at 1:29