Skip to content

Instantly share code, notes, and snippets.

@kazua
Created August 3, 2013 05:56
Show Gist options
  • Save kazua/6145365 to your computer and use it in GitHub Desktop.
Save kazua/6145365 to your computer and use it in GitHub Desktop.
Project Euler Problem 45
//http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2045
//http://projecteuler.net/index.php?section=problems&id=45
//write kazua
import scala.math._
object problem45 {
def isPenNum(d : Double) = (sqrt(1.0 + 24.0 * d) + 1.0) / 6.0 == ((sqrt(1.0 + 24.0 * d) + 1.0) / 6.0).toInt
def problem45(n : Int = 143 + 1, a : Long = 0) : Long = a match {
case a if isPenNum(a.toDouble) => a
case _ => problem45(n + 1, n * (2 * n - 1))
}
def main(args : Array[String]) {
println(problem45())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment