Created
March 23, 2015 15:52
-
-
Save FScoward/bde2ea08247d5ccb12a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main extends App { | |
// your code goes here | |
def fib(n: Int): Int = { | |
@annotation.tailrec | |
def loop(count: Int, pp: Int, p: Int): Int = { | |
// println(s"n: $n, count: $count, pp: $pp, p: $p") | |
if(count < n - 2) { | |
loop(count + 1, p, p + pp) | |
} else { | |
pp + p | |
} | |
} | |
loop(0, 0, 1) | |
} | |
println(fib(8)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment