Example #1
0
        internal static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var startDate    = ConsoleInputHelper.SafeRead <DateTime>(StartDatePrompt, WrongFormatError);
            var endDate      = ConsoleInputHelper.SafeRead <DateTime>(EndDatePrompt, WrongFormatError);
            var dayOfTheWeek = ConsoleInputHelper.SafeRead <DayOfWeek>(DayOfTheWeekPrompt, DayOfTheWeekErrorMessage);

            if (startDate > endDate)
            {
                var oldValue = startDate;
                startDate = endDate;
                endDate   = oldValue;
            }

            var numberOfDays = 0;

            for (var i = startDate; i != endDate; i = i.AddDays(1))
            {
                if (i.DayOfWeek == dayOfTheWeek)
                {
                    numberOfDays++;
                }
            }

            var message = string.Format(
                "The number of {0} between {1} and {2} is {3}",
                dayOfTheWeek,
                startDate.ToString("dd/MM/yyyy"),
                endDate.ToString("dd/MM/yyyy"),
                numberOfDays);

            ConsoleOutputHelper.WriteMessage(message, ConsoleMessageType.Success);
        }
Example #2
0
        internal static void Main(string[] args)
        {
            var intervalStart = ConsoleInputHelper.SafeRead <int>(IntervalStartPromt);
            var intervalEnd   = ConsoleInputHelper.SafeRead <int>(IntervalEndPromt);

            while (true)
            {
                var divisor        = ConsoleInputHelper.SafeRead <int>(DivisorChousePromt);
                var isDivisorValid = divisor == 3 ||
                                     divisor == 4 ||
                                     divisor == 9;

                if (!isDivisorValid)
                {
                    ConsoleOutputHelper.WriteMessage(InvalidDivisorPromt, ConsoleMessageType.Error);
                }
                else
                {
                    var numbers = GetAllDivisableNumbers(intervalStart, intervalEnd, divisor);
                    ConsoleOutputHelper.WriteMessage(numbers, ConsoleMessageType.Success);

                    break;
                }
            }
        }
Example #3
0
        internal static void Main(string[] args)
        {
            const string SampleString = "Sample <up>tagged</up> text with MANY <up>Tags</up>!";
            var          userText     = ConsoleInputHelper.SafeRead <string>(GreetingMessage);

            ConsoleOutputHelper.WriteMessage(TransformText(userText), ConsoleMessageType.Success);
        }
Example #4
0
        internal static void Main(string[] args)
        {
            var rawEqation = ConsoleInputHelper.SafeRead <string>(GreetingMessage);
            var rawIndexes = rawEqation.Split(new[] { "x^2+", "x+", "=0" }, StringSplitOptions.RemoveEmptyEntries);
            var solution   = SolveQuadraticEquation(double.Parse(rawIndexes[0]), double.Parse(rawIndexes[1]), double.Parse(rawIndexes[2]));

            ConsoleOutputHelper.WriteMessage(solution, ConsoleMessageType.Success);
        }
Example #5
0
        internal static void Main(string[] args)
        {
            int    inputNumber = ConsoleInputHelper.SafeRead <int>(GreetingMessage, ParsingErrorMessage);
            bool   isEven      = inputNumber % 2 == 0;
            string message     = string.Format(SuccessMessage, inputNumber, isEven ? "Even" : "Odd");

            ConsoleOutputHelper.WriteMessage(message, ConsoleMessageType.Success);
        }
Example #6
0
        public override void ExecuteTask()
        {
            base.ExecuteTask();

            const string SampleString = "Sample <up>tagged</up> text with MANY <up>Tags</up>!";
            var          userText     = ConsoleInputHelper.SafeRead <string>(GreetingMessage);

            this.ShowResult(this.TransformText(userText));
        }
Example #7
0
        internal static void Main(string[] args)
        {
            // Allow the user to select which special directory to start from, this can be some kind of menu or just asking about the name of the directory.
            // Ask the user about a name for the file where you will write all the information
            var specialFolder    = ConsoleInputHelper.SafeRead <Environment.SpecialFolder>();
            var directoryScanner = new DirecotryScanner();

            directoryScanner.ScanPath(Environment.GetFolderPath(specialFolder));

            // write the results above in a file with the chosen name
            // Put all the iterating actions in a method and use recursion in order to read all the files and directories in the results of the previous reading. This should continue until there are no more subdirectories found.
        }
Example #8
0
        internal static void Main(string[] args)
        {
            var inputNumber = ConsoleInputHelper.SafeRead <int>();

            if (inputNumber % 35 == 0)
            {
                ConsoleOutputHelper.WriteMessage(SuccessMessage, ConsoleMessageType.Success);
            }
            else
            {
                ConsoleOutputHelper.WriteMessage(FailMessage, ConsoleMessageType.Warrning);
            }
        }
Example #9
0
        internal static void Main(string[] args)
        {
            var arrayLength = ConsoleInputHelper.SafeRead <int>(ArrayLengthPromptMessage);

            var array = new int[arrayLength];

            for (int i = 0; i < arrayLength; i++)
            {
                array[i] = ConsoleInputHelper.SafeRead <int>(string.Format(ElementAtPositionMessage, i));
            }

            var maxList = new List <int>();

            for (int i = 0; i < array.Length - 2; i++)
            {
                for (int j = i + 1; j < array.Length - 1; j++)
                {
                    var currentDifference = array[j] - array[i];

                    var currentList = new List <int>();

                    currentList.Add(array[i]);
                    currentList.Add(array[j]);
                    var currentBorderNumber = array[j];

                    for (int k = j + 1; k < array.Length; k++)
                    {
                        if (array[k] - currentBorderNumber == currentDifference)
                        {
                            currentList.Add(array[k]);
                            currentBorderNumber = array[k];
                        }
                    }

                    if (currentList.Count > maxList.Count)
                    {
                        maxList = currentList;
                    }
                }
            }

            Console.Write("The largest increasing arithmetic progression is: ");

            foreach (var number in maxList)
            {
                Console.Write(" {0} ", number);
            }

            Console.WriteLine();
        }
Example #10
0
        internal static void Main(string[] args)
        {
            var userText   = ConsoleInputHelper.SafeRead <string>(GreetingMessage);
            var searchWord = ConsoleInputHelper.SafeRead <string>(SearchWordPromt);

            var setnaces = userText.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var setnace in setnaces)
            {
                if (setnace.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Any(x => x == searchWord))
                {
                    Console.WriteLine(setnace.Trim());
                }
            }
        }
Example #11
0
        internal static void Main(string[] args)
        {
            var arrayLength = ConsoleInputHelper.SafeRead <int>(ArreyLengthPromptMessage);
            var array       = new int[arrayLength];

            var currentLength         = 1;
            var currentSequenceNumber = 0;
            var maxSequenceNumber     = 0;
            var maxLength             = 1;

            for (int i = 0; i < array.Length; i++)
            {
                array[i] = ConsoleInputHelper.SafeRead <int>(string.Format(ElementAtPositionMessage, i));

                if (i == 0)
                {
                    currentSequenceNumber = array[i];
                    maxSequenceNumber     = currentSequenceNumber;
                    continue;
                }

                if (currentSequenceNumber == array[i])
                {
                    currentLength++;

                    if (currentLength >= maxLength)
                    {
                        maxLength         = currentLength;
                        maxSequenceNumber = currentSequenceNumber;
                    }
                }
                else
                {
                    currentLength         = 1;
                    currentSequenceNumber = array[i];
                }
            }

            Console.Write("Largest sequence:{");

            for (int i = 0; i < maxLength; i++)
            {
                Console.Write(" {0} ", maxSequenceNumber);
            }

            Console.WriteLine("}");
        }
        public override void ExecuteTask()
        {
            base.ExecuteTask();

            var userText   = ConsoleInputHelper.SafeRead <string>(GreetingMessage);
            var searchWord = ConsoleInputHelper.SafeRead <string>(SearchWordPromt);

            var setnaces = userText.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var setnace in setnaces)
            {
                if (setnace.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Any(x => x == searchWord))
                {
                    this.ShowResult(setnace.Trim());
                }
            }
        }
Example #13
0
        internal static void Main(string[] args)
        {
            var inputNumber = ConsoleInputHelper.SafeRead <int>(EnterNumberPrompt);

            while (true)
            {
                var choice        = ConsoleInputHelper.SafeRead <int>(AlgorithmChoosePrompt);
                var choiseIsValid = choice == 1 || choice == 2;

                if (choiseIsValid)
                {
                    RunAlgorithm(choice, inputNumber);
                    break;
                }

                ConsoleOutputHelper.WriteMessage(InlvaidChoicePrompt, ConsoleMessageType.Error);
            }
        }
Example #14
0
        internal static void Main(string[] args)
        {
            var sides = new double[TriangleNumberOfSides];

            for (int i = 0; i < TriangleNumberOfSides; i++)
            {
                var promtMessage = string.Format(SidePromtMessage, i + 1);
                sides[i] = ConsoleInputHelper.SafeRead <double>(promtMessage);
            }

            var perimeter = sides.Sum();
            var area      = sides.Aggregate((a, b) => a * b);

            var areaMessage      = string.Format(AreaSuccessMessage, area);
            var perimeterMessage = string.Format(PerimeterSuccessMessage, perimeter);

            ConsoleOutputHelper.WriteMessage(areaMessage, ConsoleMessageType.Success);
            ConsoleOutputHelper.WriteMessage(perimeterMessage, ConsoleMessageType.Success);
        }
Example #15
0
        internal static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            ExtractBirthDateFormString("9204028463");

            string pinString;

            while (true)
            {
                pinString = ConsoleInputHelper.SafeRead <string>(PinInputGreeting);

                var parsedPin       = 0L;
                var isNummeric      = long.TryParse(pinString, out parsedPin);
                var isCorrectLength = pinString.Length == 10;

                if (isNummeric && isCorrectLength)
                {
                    break;
                }

                ConsoleOutputHelper.WriteMessage(InvalidPinPromt, ConsoleMessageType.Error);
            }

            var birthDay          = ExtractBirthDateFormString(pinString);
            var gender            = ExtractGender(pinString);
            var age               = ExtratAge(pinString);
            var daysUntilBirthDay = ExtractDaysUntilBirthDay(pinString);

            var message =
                string.Format(
                    "The person wtih the PIN {0} is {1} and is born on: {2}. He is {3} years old and has {4} days until his birthday.",
                    pinString,
                    gender,
                    birthDay.ToString("dd/MM/yyyy"),
                    age,
                    daysUntilBirthDay);

            ConsoleOutputHelper.WriteMessage(message, ConsoleMessageType.Success);
        }
Example #16
0
        internal static void Main(string[] args)
        {
            var firstArraySize = ConsoleInputHelper.SafeRead <int>(FirstArraySizeMessage);
            var firstArray     = new int[firstArraySize];

            for (int i = 0; i < firstArray.Length; i++)
            {
                firstArray[i] = ConsoleInputHelper.SafeRead <int>(string.Format(EnterElementMessage, i));
            }

            var secondArraySize = ConsoleInputHelper.SafeRead <int>(SecondArraySizeMessage);
            var secondArray     = new int[secondArraySize];

            for (int i = 0; i < secondArray.Length; i++)
            {
                secondArray[i] = ConsoleInputHelper.SafeRead <int>(string.Format(EnterElementMessage, i));
            }

            var equalElements = firstArray.Where(secondArray.Contains).ToList();

            ConsoleOutputHelper.WriteMessage(string.Format(BiggestElementMessage, equalElements.Max()), ConsoleMessageType.Success);
        }
Example #17
0
        internal static void Main(string[] args)
        {
            var arrayLength   = ConsoleInputHelper.SafeRead <int>(ArrayLengthPromptMessage);
            var sequenceCount = ConsoleInputHelper.SafeRead <int>(SequanceLengthMessage);
            var array         = new int[arrayLength];

            for (int i = 0; i < arrayLength; i++)
            {
                array[i] = ConsoleInputHelper.SafeRead <int>(string.Format(ElementAtPositionMessage, i));
            }

            var maxSum   = 0;
            var maxIndex = -1;

            for (int i = 0; i < arrayLength - sequenceCount + 1; i++)
            {
                var currentSum = 0;

                for (int j = 0; j < sequenceCount; j++)
                {
                    currentSum += array[i + j];
                }

                if (currentSum > maxSum)
                {
                    maxSum   = currentSum;
                    maxIndex = i;
                }
            }

            Console.Write("The sequence of {0} elements with maximal sum is:  ", sequenceCount);

            for (int i = maxIndex; i < maxIndex + sequenceCount; i++)
            {
                Console.Write(" {0}; ", array[i]);
            }

            Console.WriteLine();
        }
Example #18
0
        internal static void Main(string[] args)
        {
            var length          = ConsoleInputHelper.SafeRead <int>(ArrayLengthPromptMessage);
            var array           = new int[length];
            var count           = 1;
            var maxcount        = 0;
            var maxcountNumbers = 1;
            var lastNumber      = 0;
            var sequences       = new int[length];

            ConsoleOutputHelper.WriteMessage(ArrayValuesPrompt);

            for (int i = 0; i < length; i++)
            {
                array[i] = ConsoleInputHelper.SafeRead <int>(string.Format(ElementAtPositionMessage, i));

                if (i > 0 && array[i] == array[i - 1] + 1)
                {
                    count++;

                    if (count > maxcount)
                    {
                        maxcount   = count;
                        lastNumber = array[i];
                        Array.Clear(sequences, 0, length);
                        maxcountNumbers = 1;
                    }
                    else if (count == maxcount)
                    {
                        maxcountNumbers++;
                        sequences[i] = array[i];
                    }
                }
                else
                {
                    count = 1;
                }
            }

            if (maxcountNumbers == 1)
            {
                if (maxcount <= 1)
                {
                    ConsoleOutputHelper.WriteMessage(NoSequanceMesssage, ConsoleMessageType.Warrning);
                }
                else
                {
                    ConsoleOutputHelper.WriteMessage(MaxSequanceMesssage, ConsoleMessageType.Success);

                    for (int i = maxcount - 1; i >= 0; i--)
                    {
                        Console.Write((lastNumber - i) + " ");
                    }
                }
            }
            else
            {
                ConsoleOutputHelper.WriteMessage(MaxSequanceMesssage, ConsoleMessageType.Success);

                for (int i = maxcount - 1; i >= 0; i--)
                {
                    Console.Write((lastNumber - i) + " ");
                }

                Console.WriteLine();

                foreach (int number in sequences.Where(number => number != 0))
                {
                    for (int i = maxcount - 1; i >= 0; i--)
                    {
                        Console.Write((number - i) + " ");
                    }
                }
            }
        }