Question: Please help import in haskell - without using a triple recursion call (for example: trib n = trib (n-1)+trib (n-2)+trib (n-3)) refer to specs and
Please help import in haskell - without using a triple recursion call (for example: trib n = trib (n-1)+trib (n-2)+trib (n-3))
refer to specs and sample output below, thanks!

trib trib :: Int -> Int Given a non-negative integer n, calculate the nth tribonnaci number (where values arc the sums of the previous three items in the sequence, or 1 when there aren't enough values ahead of it). For our purposes, the sequence begins as 1,1,1,.... You need to implement a fast version; if your code takes some exponential amount of time to complete, you will not get credit for this function. Hint: this is a time when even Haskell's laziness/memoizing behavior can't save the naive triply-recursive approach! *Homework3> trib 0 Homework3> trib 1 Homework3> trib 2 Homework3> trib 3 Homework3> trib 4 Homework3> trib 5 *Homework3> trib 6 17 Homework3> take 20 map trib [1..1 [1,1,3,5,9,17,31,57,105,193,355,653,1201,2209,4063,7473,13745,25281,46499,85525] trib trib :: Int -> Int Given a non-negative integer n, calculate the nth tribonnaci number (where values arc the sums of the previous three items in the sequence, or 1 when there aren't enough values ahead of it). For our purposes, the sequence begins as 1,1,1,.... You need to implement a fast version; if your code takes some exponential amount of time to complete, you will not get credit for this function. Hint: this is a time when even Haskell's laziness/memoizing behavior can't save the naive triply-recursive approach! *Homework3> trib 0 Homework3> trib 1 Homework3> trib 2 Homework3> trib 3 Homework3> trib 4 Homework3> trib 5 *Homework3> trib 6 17 Homework3> take 20 map trib [1..1 [1,1,3,5,9,17,31,57,105,193,355,653,1201,2209,4063,7473,13745,25281,46499,85525]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
