Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def qfib(n: Int) = {
- match n {
- case 1 => 1
- case 2 => 3
- case 3 => 5
- case _ => tail_qfib(n, 1, 3, 5, 0)
- }
- def tail_qfib(n: Int, a: Int, b: Int, c: Int, acc: Int) = {
- match n {
- case 0 => acc
- case _ => tail_qfib(n-1, b, c, acc, 3 * c + 2 * b - a)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement