Skip to content

Instantly share code, notes, and snippets.

@daiksy
Created November 21, 2012 16:21
Show Gist options
  • Select an option

  • Save daiksy/4125799 to your computer and use it in GitHub Desktop.

Select an option

Save daiksy/4125799 to your computer and use it in GitHub Desktop.
Project Euler Problem 8
/**
* http://projecteuler.net/problem=8
* http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%208
*/
val s = "7316717 ... 63450" // 途中省略してます.
val xs = s.toList.map(_.toString.toInt)
def product(xs: List[Int], ys: List[Int]): List[Int] = {
xs match {
case a :: b :: c :: d :: e :: tail => product(xs.tail, a * b * c * d * e :: ys)
case _ => ys
}
}
val ret = product(xs, Nil) max
println(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment