svetlozar_kirkov

Tribonacci Triangle

Dec 15th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Numerics;
  4.  
  5. namespace TribonacciTriangle
  6. {
  7.     class TribonacciTriangle
  8.     {
  9.         static void Main()
  10.         {
  11.             List<BigInteger> tribonacciNums = new List<BigInteger>();
  12.             for (int i = 0; i < 3; i++)
  13.             {
  14.                 tribonacciNums.Add(BigInteger.Parse(Console.ReadLine()));
  15.             }
  16.             int lines = int.Parse(Console.ReadLine());
  17.             Console.WriteLine(tribonacciNums[0]);
  18.             Console.WriteLine("{0} {1}",tribonacciNums[1],tribonacciNums[2]);
  19.             if (lines==2)
  20.             {
  21.                 return;
  22.             }
  23.             else
  24.             {
  25.                 BigInteger currentTrib;
  26.                 BigInteger firstTrib = tribonacciNums[0];
  27.                 BigInteger secondTrib = tribonacciNums[1];
  28.                 BigInteger thirdTrib = tribonacciNums[2];
  29.                 for (int i = 0; i < 220; i++)
  30.                 {
  31.                     currentTrib = firstTrib + secondTrib + thirdTrib;
  32.                     tribonacciNums.Add(currentTrib);
  33.                     firstTrib = secondTrib;
  34.                     secondTrib = thirdTrib;
  35.                     thirdTrib = currentTrib;
  36.                 }
  37.                 int currentTribIndex = 3;
  38.                 int currentLineLength = 3;
  39.                 for (int i = 0; i < lines-2; i++)
  40.                 {
  41.                     for (int k = 0; k < currentLineLength; k++)
  42.                     {
  43.                         Console.Write("{0} ",tribonacciNums[currentTribIndex]);
  44.                         currentTribIndex++;
  45.                     }
  46.                     Console.WriteLine();
  47.                     currentLineLength++;
  48.                 }
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment