Last active
August 29, 2015 13:59
-
-
Save pmashchak/10519170 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# reverse decimal int number | |
# without converting to string | |
def reverse_decimal num | |
while num > 0 do | |
# condition | |
last = num % 10 | |
# algorithm body | |
res ||= 0 | |
res = (res *= 10) + last | |
# decrement | |
num /= 10 | |
end | |
res | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment