Euler problem 25

Here’s scala solution, the fibonacci tail recrusion method is taken from pastebin

object Prob25 {
  def main(args: Array[String]) = {
    
    // Found this in internet
    def f(n: Int) = f_tr(n, 1, 0)

    def f_tr(n: Int, b: BigInt, a: BigInt): BigInt = n match {
      case 0 => a
      case _ => f_tr(n - 1, a + b, b)
    }

    var nth: Int = 1
    val digits = 1000
    while (f(nth).toString.length < digits) {
      // for debugging the right sequance
      //println(nth + " " + f(nth).toString)
      nth += 1
    }

    println(nth)

  }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s