Skip to main content

Tribonacci sequence

Submitted by daniel on

The Tribonacci sequence is a sequence of integers Tn defined by 

T0=0, T1=T2=1, Tn=Tn−1+Tn−2+Tn−3

In other words at least the first three numbers are required before you can calculate the subsequent numbers. To calculate a number I am going to use is a simple recursive function used to figure out the Tn. when called by the printTrib() function that iterates though each number until we reach the 0 at which point we can return the Tribonacci number we are looking for.

const printTribRec = function (number) {

  if (number == 0)
    return 0;

  if (number == 1 || number == 2)
    return 1;

  else
    return printTribRec(number - 1) +
      printTribRec(number - 2) +
      printTribRec(number - 3);
}

const printTrib = function (number) {
  return printTribRec(number);
}

// Pass any number. Here we pass 6 (the 7th number as the index starts as 0)
printTrib(6);  // returns 13

The Tribonacci sequence begins 0, 1, 1, 2, 4, 7, 13, 24, 44, 81 ...

by comparison:

The Fibonacci sequence  begins 0, 1, 1, 2, 3, 5,  8,  13, 21, 34, ...

Perhaps in your next Agile Estimation or Sizing session you could try using Tribonacci sequence instead?

References

https://www.geeksforgeeks.org/tribonacci-numbers/

https://brilliant.org/wiki/tribonacci-sequence/

https://www.algebra.com/algebra/homework/Sequences-and-series/Sequences…

 

 

Add new comment

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.