Skip to content

Instantly share code, notes, and snippets.

@pokutuna
Created September 22, 2012 08:09
Show Gist options
  • Save pokutuna/3765519 to your computer and use it in GitHub Desktop.
Save pokutuna/3765519 to your computer and use it in GitHub Desktop.
@annotation.tailrec
def findTheCubedNum(num: BigInt, cache: Map[String, List[BigInt]]): BigInt = {
val cubed = num.pow(3)
val key = cubed.toString.sortWith(_ < _)
val nums = cubed :: cache.getOrElse(key, List[BigInt]())
if (nums.length == 5) return nums.min
findTheCubedNum(num + 1, cache.updated(key, nums))
}
val answer = findTheCubedNum( BigInt(1), Map[String, List[BigInt]]() )
println(answer) // => 127035954683
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment