Advertisement
TheRedRover

Untitled

Apr 5th, 2020
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.44 KB | None | 0 0
  1. object Tribonacci {
  2. def helper[T : Numeric](sign:List[T],n:Int,answ:List[T], i:Int): List[T] =
  3.   {
  4.     val l = sign.sum
  5.     val answ1=(answ.concat(List(l)))
  6.     val sign1 = List(sign(1),sign(2),answ1.last)
  7.     if(i<n-4) helper(sign1, n, answ1, i+1)
  8.     else answ1
  9.   }
  10.  def tribonacci[T : Numeric](signature: List[T], n: Int): List[T] = {
  11.     if(n==0) List()
  12.     else if(n<3)List(signature(n-1))
  13.     else helper(signature, n, signature,0)
  14.   }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement