/*
    Ingus Zemturis
    Gupa: 110
    Compiler: Visual Studio
*/
using System;

namespace ConsoleApp1
{
    internal class Program
    {
        static void factorial(int f) // f! pieejams ērtā iepakojumā 1. uzdevums
        {
            for (int i = f - 1; i > 1; i--)
            {
                f = f * i;
            }
            Console.WriteLine(f);
        }
        static void MultiplicationTable(int t) // reizrēķina tabula 2. uzdevums
        {
            for (int i = 1; i <= t; i++)
            {
                Console.Write("\n");
                for (int j = 1; j <= t; j++)
                {
                    Console.Write($"\t {i * j}");
                }
            }
            Console.Write("\n");
        }

        static void theTrueAndRealTable(int[,] Table) // tagad ar papildus dimensijām! 3. uzdevums
        {
            int i = 0;
            int j = 0;

            while (i < Table.GetLength(0)) // "the name 'i' does not exist in the current context"
            {
                Console.Write("\n");
                for (j = 0; j < Table.GetLength(1); j++)
                {
                    Console.Write($"  {Table[i, j]}");
                }
                i++;
            }
            i = Table.GetLength(0) - 1;
            Console.WriteLine("\n");


            while (i >= 0)
            {
                Console.Write("\n");
                for (j = 0; j < Table.GetLength(1); j++)
                {
                    Console.Write($"  {Table[i, j]}");
                }
                i--;
            }

            Console.WriteLine("\n");
            int XshotSum = 0, YshotSum = 0;

            for (int t = 0; t < Table.GetLength(0); t++)
            {
                for (j = 0; j < Table.GetLength(1); j++)
                {
                    XshotSum = XshotSum + Table[t, j];
                }
                Console.Write($" {XshotSum}");
                XshotSum = 0;
            }


            Console.Write("\n");
            int Rows = Table.GetLength(0);
            int columns = Table.GetLength(1);
            for (int t = 0; t < columns; t++)
            {
                for (j = 0; j < Rows; j++)
                {
                    if (j <= Table.GetLength(0))
                    {
                        YshotSum = YshotSum + Table[j, t];
                    }
                    else
                    {
                        continue;
                    }

                }
                Console.Write($" {YshotSum}");
                YshotSum = 0;
            }
            Console.WriteLine("\n");

        }

        static void listThoseNumbers(List<int> numberList)
        {
            int minimalizm = 999;
            int maximality = 0;
            int averageJoe = 0;

            for (int i = 0; i < numberList.Count; i++)
            {
                if (minimalizm > numberList[i])
                {
                    minimalizm = numberList[i];
                }
                if (maximality < numberList[i])
                {
                    maximality = numberList[i];
                }
            }
            averageJoe = numberList.Sum() / numberList.Count;
            Console.WriteLine($" lielaakais: {maximality}  mazaakais: {minimalizm}   videejais: {averageJoe}\n");
        }

        static void theWorstTaskYet(string notAnumber) // 4.555555555555555555555555555555555555555555555555555555555555555555555555
        {
            List<string> twoAndSomeOddNumbers = notAnumber.Split().ToList();
            List<int> extraCounter = new List<int>();
            int oneAndAlmostTwoNumbers = 0;
            for (int i = 0; i < twoAndSomeOddNumbers.Count; i++)
            {
                oneAndAlmostTwoNumbers = Convert.ToInt32(twoAndSomeOddNumbers[i]);
                extraCounter.Add(oneAndAlmostTwoNumbers);
            }

            List<int> PositiveNumber = new List<int>();

            for (int i = 0; i < twoAndSomeOddNumbers.Count; i++)
            {
                if (extraCounter[i] < 0)
                {
                    continue;
                }
                else
                {
                    PositiveNumber.Add(extraCounter[i]);
                }

            }

            for (int i = 0; i < PositiveNumber.Count; i++)
            {
                Console.Write($"  {PositiveNumber[i]}");

            }
        }



        static void Main(string[] args)
        {
            Random rng = new Random();
            int RandomNumber = 0;


            factorial(5);

            Console.WriteLine("cik lielu multiplikaacijas tabulu tu gribi? ");
            int tableOfMultiplayer = Convert.ToInt32(Console.ReadLine());
            MultiplicationTable(tableOfMultiplayer);

            int[,] tableNEO =
                {
                {1, 2, 3},
                {4, 5, 6},
                {7, 8, 9}
               }; // var mainīt masīva saturu, un kodam joprojām vajadzētu darboties

            theTrueAndRealTable(tableNEO);


            // 4.1
            List<int> numerika = new List<int>() { 2, 5, 7, 8, 12, 13, 14, 15, 17, 13 };
            numerika.Reverse();
            for (int i = 0; i < numerika.Count; i++)
            {
                Console.Write($"  {numerika[i]}");
            }

            // 4.3
            List<string> MicrosoftWord = new List<string>() { "bumbieris", "pineapple", "john", "cross", "dzeltens", "dorito" };
            MicrosoftWord.Sort();

            for (int i = 0; i < MicrosoftWord.Count; i++)
            {
                Console.Write($"  {MicrosoftWord[i]}");
            }
            // 4.2

            List<int> theFalseAndIllusionaryNumbers = new List<int>() { };
            for (int i = 0; i < 20; i++)
            {
                RandomNumber = rng.Next(1, 999);
                theFalseAndIllusionaryNumbers.Add(RandomNumber);
            }
            Console.WriteLine("\n");

            listThoseNumbers(theFalseAndIllusionaryNumbers);

            // 4.4
            Console.WriteLine("ievadi teikumu");

            string? sentenceOfWords = Console.ReadLine();

            string[] words = sentenceOfWords.Split();

            List<string> lonelyWords = new List<string>(words);

            for (int i = 0; i < lonelyWords.Count; i++)
            {
                Console.Write($"  {lonelyWords[i]}");
            }

            // 4.5

            Console.WriteLine("\n ievadi skaitlus: ");
            string fourAndAhalfNumbers = Console.ReadLine();
            theWorstTaskYet(fourAndAhalfNumbers);

            // 5

            int value1 = 0;
            int value2 = 1;
            int value3 = 0;

            Console.Write("\n\nfibonaci virkne iterativi:");
            for (int i = 0; i <= 20; i++)
            {
                Console.Write($"  {value1}");
                value3 = value1 + value2;
                value1 = value2;
                value2 = value3;
            }


        }
    }
}
