Advertisement
Kuncavia

tribonacci

Feb 25th, 2019
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Input: '1', '0', '5', '5' (line = 5)
  2. // Expect output:
  3. // 1
  4. // 0 5
  5. // 6 11 22
  6. // 39 72 133 244
  7. // 449 826 1519 2794 5139
  8.  
  9. // Output:
  10. // 1
  11. // 0 5
  12. // 6 11 22
  13. // 39 72 133 244
  14. // 39 72 133 244 449 826 1519 2794 5139
  15.  
  16.  
  17. let firstNum = +gets();
  18. let secondNum = +gets();
  19. let thirdNum = +gets();
  20. let line = +gets();
  21. let array = [];
  22.  
  23. print(firstNum);
  24. print(secondNum, thirdNum);
  25.  
  26. if (line > 2) {
  27.     for (let i = 3; i <= line; i++) {
  28.         for (let j = 0; j < i; j++) {
  29.             let tempNum = firstNum + secondNum + thirdNum;
  30.             firstNum = secondNum;
  31.             secondNum = thirdNum;
  32.             thirdNum = tempNum;
  33.             array.push(thirdNum);
  34.         }
  35.         if (array.length === 3) {
  36.             print(array.toString().replace(/,/g, ' '));
  37.         } else {
  38.             print(array.slice(3).toString().replace(/,/g, ' '));
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement