Skip to content

Instantly share code, notes, and snippets.

@agush22
Created January 6, 2013 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agush22/4465642 to your computer and use it in GitHub Desktop.
Save agush22/4465642 to your computer and use it in GitHub Desktop.
Flip a number without changing it to string
def flipnum num
res = 0
mag = magnitude(num)
neg = true if num < 0
num = num.abs
while num > 0
mag -= 1
res += (num % 10)* 10 ** mag
num = num/10
end
unless neg
res
else
res * -1
end
end
def magnitude num
num = num.abs
count = 0
while num > 0
count += 1
num = num/10
end
count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment