Skip to content

Instantly share code, notes, and snippets.

@andrewconner
Last active December 20, 2015 22:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save andrewconner/6202431 to your computer and use it in GitHub Desktop.
// Reverses an integer without using Strings
def reverse(n: Int): Int = {
val len = math.ceil(math.log10(n+1)).toInt
Stream.continually(n).take(len).zipWithIndex
.map{ case (m,p) =>
(m % math.pow(10, len-p) / math.pow(10, len-p-1)).toInt * math.pow(10,p)
}
.sum.toInt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment