re: Daily Coding Puzzles - Oct 29th - Nov 2nd VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Wednesday Write a program to reverse the digits of a positive integer but without converting it to a string.
 

My Python solution:

def reverse_number(num, running_value=0):
    if num == 0: 
        return running_value // 10
    quotient, remainder = divmod(num, 10)
    running_value += remainder
    return reverse_number(quotient, running_value * 10)

print(reverse_number(123456))
print(reverse_number(5))
 
 
>>> print(reverse_number(1234567890))
987654321

You did not pass.

987654321 is how I expect it to work though without the 0 in the beginning as you should return a positive integer.

That was not a part of the question, so I would say that the result should still start with a 0.

the positive integer shouldn't have a leading zero I don't think. It's at least up to interpretation.

code of conduct - report abuse