Talk:Middle three digits: Difference between revisions

Line 11:
==C++ entry and generalization to other numbers of digits==
The check rejecting the cases where (len % 2 == 0) is only correct if the length is also odd. It's perfectly reasonable to request the middle 2 digits of a 4-digit number, etc. So the correct check is to reject the case where the length of the string does not have the same parity as the number of digits being requested (len % 2 != n % 2). [[User:Markjreed|Markjreed]] 05:13, 5 February 2013 (UTC)
 
==Musings on the type of the return value==
The type of the return value from the function is, (purposely), not specified in the requirements. For good input, I returned a string in the Python version as
# I found it easier to compute the answer by manipulating the string representation of the input integer, and,
# I had already thought that the function might have to return answers with leading zeroes.
 
Others have functions that return integers. It is just as valid, just different. I guess the middle three digits can be calculated with modulo arithmetic and without any use of strings. In that case it may be easier to return the integer result and rely on output formatting to zero-extend results to three digits on printing? Different strokes and all that. --[[User:Paddy3118|Paddy3118]] 07:01, 5 February 2013 (UTC)
Anonymous user