/// <summary> /// The function calulate the area of both Inner and outter square, and print the differences. /// They are two squares: a smaller and a bigger one. The smaller square is in a cirle circumcircles and /// bigger square is on the incircle(outside). /// </summary> /// <param name="radius"></param> public static void DiffercesOfTwoSquare(double radius) { /* Problem: A cirle and two squares * _______________________________________________________________________________________ * Imagine a circle and two squares: a smaller and a bigger one. * For the smaller one, the circle is a circumcircle and for the bigger one, an incircle. * _______________________________________________________________________________________ * * So we are givin the radius of the circle. Which we use to find the area of the inner sqaure * and outter square. Then subtrace both areas to find the differces. * Formula for differences --------> Outter square - Innder square = Differences. */ double diameter = radius * 2; double side = (diameter / 2) * Math.Sqrt(2); /* The formula of a square is [side * side = Area]*/ double area1 = side * side; double area2 = diameter * diameter; /* The formula for differences. */ double difference = Math.Ceiling((area2 - area1)); ConsoleExtras.ColoredText($"A circle and two squares. Radius: {radius}", ConsoleColor.Yellow); Console.WriteLine($"The differences of the Inner and outter." + $"\nArea: {difference}\n"); }
/// <summary> /// This function searchs for a world in a string(text), if it finds it it will tell you the index, if not then retun a string that it can find it. /// </summary> /// <param name="word"></param> /// <param name="text"></param> public static void FindTheWord(string word, string text) { ConsoleExtras.ColoredText("Fin the word", ConsoleColor.Blue); string search = text.Contains(word) || text.Contains(word) ? $"The word [{word}] is in index {text.IndexOf(word)}" : $"The world {word} is not found"; Console.WriteLine(search); ConsoleExtras.ColoredText(text + "\n", ConsoleColor.DarkYellow); }
/// <summary> /// calculates how many dots exist in a pentagonal shape around the center dot on the Nth iteration. /// Formula: (5(n^2) - 5n + 2) / 2 /// </summary> /// <param name="number"></param> public static void CenteredPentagonal(int number) { double soultion; soultion = ((5 * (Math.Pow(number, 2)) - (5 * number) + 2)) / 2; ConsoleExtras.ColoredText("Centerd Pentagonal", ConsoleColor.Green); Console.WriteLine(soultion + "\n"); }
/// <summary> /// Take a number and returns the specified amount of multiple of that number. Yes this is a static function. /// </summary> /// <param name="multiple"></param> /// <param name="lenght"></param> public static void ArrayOfMultiples(int multiple, int lenght) { ConsoleExtras.ColoredText("Array Of Multiples.", ConsoleColor.Cyan); Console.Write($"Array of multiples({multiple}, {lenght}) ->["); int solution = multiple; for (int i = 0; i != lenght; i++) { solution = multiple * (i + 1); var print = (i + 2) <= lenght ? $"{solution}, " : $"{solution}"; Console.Write(print); } Console.Write("]\n\n"); }
/// <summary> /// It finds the largest number from three array list and put them in a arraylist. /// I just printed them insted because I dont feel like making a loop to print them all. /// </summary> /// <param name="list1"></param> /// <param name="list2"></param> /// <param name="list3"></param> public static void SortLargestArray(List <int> list1, List <int> list2, List <int> list3) { int numberOfElements = 0; int storedValue = 0; List <int> MasterList = new List <int>(); ConsoleExtras.ColoredText("Sort the larger from three array list.", ConsoleColor.Cyan); for (int i = 0; i != 3; i++) { switch (i) { case 0: numberOfElements = list1.Count(); MasterList = list1; break; case 1: numberOfElements = list2.Count(); MasterList = list2; break; case 2: numberOfElements = list3.Count(); MasterList = list3; break; } for (int t = 0; t < numberOfElements - 1; t++) { storedValue = MasterList[t]; if (storedValue > MasterList[t + 1]) { storedValue = MasterList[t]; } else { storedValue = MasterList[t + 1]; } if (t == numberOfElements - 2) { Console.WriteLine(storedValue); } // I could add this to a list or an array, but I dont feel like looping to print it. } } }
static void Main(string[] args) { DynamicProgramming dynamicProgramming = new DynamicProgramming(); /* ProblemMedium.ArrayOfMultiples(7, 5); * ProblemMedium.ArrayOfMultiples(12, 10); * ProblemMedium.ArrayOfMultiples(17, 6);*/ // ProblemMedium.FindTheWord("Diver", "I like to Diver Cards."); /*VariablesThings variables = new VariablesThings(); * variables.AddListValuesSort(); // This adds all the values to all three array list. didn't want to messy up program class. * ProblemMedium.SortLargestArray(variables.NumberTest1,variables.NumberTest2,variables.NumberTest3);*/ /* ProblemMedium.DiffercesOfTwoSquare(5); * ProblemMedium.DiffercesOfTwoSquare(6); * ProblemMedium.DiffercesOfTwoSquare(7);*/ /*ProblemMedium.CenteredPentagonal(1); * ProblemMedium.CenteredPentagonal(2); * ProblemMedium.CenteredPentagonal(3); * ProblemMedium.CenteredPentagonal(8);*/ // ConsoleExtras.ColoredText("Fibonacci",ConsoleColor.Cyan); // Console.WriteLine( dynamicProgramming.FibonacciSequence(12)); // Console.WriteLine(dynamicProgramming.FibonacciSequenceMemoizion(200)); //Console.WriteLine(dynamicProgramming.GridTravler(18, 18)); // Dictionary<string, ulong> gridDictionary = new Dictionary<string, ulong>(); // Console.WriteLine(dynamicProgramming.GridTravlerMemoize(100, 100,gridDictionary)); //ApplyedMath applyedMath = new ApplyedMath(); //applyedMath.DivideComplexNumbers("6+3i/7-5i"); //applyedMath.DivideComplexNumbers("-32+8i/5+3i"); //applyedMath.DivideComplexNumbers("25+19i/5-3i"); //applyedMath.DivideComplexNumbers("-23+11i/5+1i"); //applyedMath.DivideComplexNumbers("2-8i/3+5i"); //applyedMath.DivideComplexNumbers("2-16i / - 3 - 1i"); // Remove Duplicates from Sorted Array /* int[] DuplicatedArray = { 4, 4, 4, 5, 5, 8, 8, 10,10, 22 }; * * int len = ProblemMedium.RemoveDuplicates(DuplicatedArray); * for (int i = 0; i < len; i++) * { * Console.Write(DuplicatedArray[i] +", "); * } */ int[] numList = { 100, 99, 89, 72, 54, 52, 34, 30, 16, 15, 14, 10, 5, 4, 2 }; //int[] numList = { 20, 20, 40, 44, 48, 50, 54 }; int target = 42; Console.WriteLine("Array of numbers"); Console.Write("Where is "); ConsoleExtras.ColoredWrite(target.ToString(), ConsoleColor.Green); Console.Write(" located in the array.\n"); // Print array. for (int i = 0; i < numList.Length; i++) { if (i == numList.Length - 1) { ConsoleExtras.ColoredWrite($"{numList[i]}\n", ConsoleColor.DarkYellow); break; } ConsoleExtras.ColoredWrite($"{numList[i]}, ", ConsoleColor.DarkYellow); } Console.WriteLine($"Index: {DynamicProgramming.BinarySearch(numList,target)}"); }
/// <summary> /// Binary Search. /// It search for an index in a ordered list. /// </summary> /// <param name="Array"></param> /// <param name="target"></param> /// <returns></returns> public static int BinarySearch(int[] Array, int target) { bool leaseToGreater = false; // Checking to see is Array is order from lease to greatest. for (int i = 0; i < Array.Length; i++) { if (i + 1 > Array.Length - 1) { break; } if (Array[i] == Array[i + 1]) { continue; } if (Array[i] < Array[i + 1]) { leaseToGreater = true; break; } else { leaseToGreater = false; break; } } ConsoleExtras.DotLoadingAnimation("Checking Array a stortment", 200, 5); // DEBUGING int low = 0, high = Array.Length - 1, mid = 0; int steps = 1; // DEBUGING switch (leaseToGreater) { case true: ConsoleExtras.ColoredText("Array is storted from least to greatest." , ConsoleColor.Green); // DEBUGING while (low <= high) { mid = (low + high) / 2; #region Debuging ConsoleExtras.ColoredWrite($"{steps}. ", ConsoleColor.Cyan); // DEBUGING for (int i = low; i < high + 1; i++) { if (i == high && i == low && Array[i] == target) { ConsoleExtras.ColoredWrite(Array[i].ToString(), ConsoleColor.Green); break; } else if (i == high && i == low && Array[i] != target) { ConsoleExtras.ColoredWrite($"Array dose not contain {target}.", ConsoleColor.Red); break; } if (i == high) { ConsoleExtras.ColoredWrite($"{Array[i]}", ConsoleColor.Blue); break; } if (i == mid) { ConsoleExtras.ColoredWrite($"{Array[i]},", ConsoleColor.DarkRed); } else if (i == low) { ConsoleExtras.ColoredWrite($"{Array[i]}", ConsoleColor.Blue); Console.Write(","); } else { Console.Write($"{Array[i]},"); } } Console.Write("\n"); steps++; // DEBUGING Thread.Sleep(1000); // DEBUGING #endregion if (Array[mid] == target) { return(mid); } else if (Array[mid] > target) { high = mid - 1; } else if (Array[mid] < target) { low = mid + 1; } } break; case false: ConsoleExtras.ColoredText("Array is storted from greatest to least." , ConsoleColor.Cyan); // DEBUGING while (low <= high) { mid = (low + high) / 2; #region Debuging ConsoleExtras.ColoredWrite($"{steps}. ", ConsoleColor.Cyan); // DEBUGING for (int i = low; i < high + 1; i++) { if (i == high && i == low && Array[i] == target) { ConsoleExtras.ColoredWrite(Array[i].ToString(), ConsoleColor.Green); break; } else if (i == high && i == low && Array[i] != target) { ConsoleExtras.ColoredWrite($"Array dose not contain {target}.", ConsoleColor.Red); break; } if (i == high) { ConsoleExtras.ColoredWrite($"{Array[i]}", ConsoleColor.Blue); break; } if (i == mid) { ConsoleExtras.ColoredWrite($"{Array[i]},", ConsoleColor.DarkRed); } else if (i == low) { ConsoleExtras.ColoredWrite($"{Array[i]}", ConsoleColor.Blue); Console.Write(","); } else { Console.Write($"{Array[i]},"); } } Console.Write("\n"); Thread.Sleep(1000); // DEBUGING steps++; // DEBUGING #endregion if (Array[mid] == target) { return(mid); } else if (Array[mid] < target) { high = mid - 1; } else if (Array[mid] > target) { low = mid + 1; } } break; } return(-1); }