Skip to content

Instantly share code, notes, and snippets.

@chrisbnt
Created September 20, 2010 13:03
Show Gist options
  • Save chrisbnt/587865 to your computer and use it in GitHub Desktop.
Save chrisbnt/587865 to your computer and use it in GitHub Desktop.
Integer#split_digits
# Efficient way of splitting digits in positive integers
class Integer
def split_digits(base = 10)
digits = []
head = self
while head >= base
digits.push head % base
head /= base
end
digits.push(head)
digits.reverse!
digits
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment