예제 #1
0
        public void Test_IsPrimeWithHighProbability()
        {
            Solutions s = new Solutions();

            Assert.IsTrue(IsPrime.SolutionWithHighProbability(11, 3));
            Assert.IsFalse(IsPrime.SolutionWithHighProbability(15, 3));
        }
예제 #2
0
파일: Input.cs 프로젝트: antomys/PM_HW_9
        public async Task TestIsPrime(HttpClient httpClient)
        {
            var tasks = IsPrime
                        .Select(pair => InternalTestIsPrime(httpClient, pair.Key, pair.Value));

            await Task.WhenAll(tasks);
        }
예제 #3
0
        public void Test_IsPrime2()
        {
            Solutions s = new Solutions();

            Assert.IsTrue(IsPrime.Solution2(11));
            Assert.IsFalse(IsPrime.Solution2(15));
            Assert.IsFalse(IsPrime.Solution2(1));
        }
        public void GreaterThanOne_NumberIsGreaterThanOne_True()
        {
            //Arrange
            IsPrime testPrime = new IsPrime();
            int     Factor    = 2;

            //Act
            bool NTest = testPrime.GreaterThanOne(Factor);

            //Assert
            Assert.AreEqual(true, NTest);
        }
        public void PrimeChecker_NumberIsPrime_True()
        {
            //Arrange
            IsPrime testPrime = new IsPrime();
            int     Factor    = 5;

            //Act
            bool FTest = testPrime.PrimeChecker(Factor);

            //Assert
            Assert.AreEqual(true, FTest);
        }
        public void PrimeLister_NumbersWillReturnChronologically_True()
        {
            //Arrange
            IsPrime testPrime = new IsPrime();
            int     Factor    = 7;

            //Act
            testPrime.PrimeLister(Factor);
            int NumberOfPrimes = _primes.Length();

            // int PTest[] = testPrime.PrimeLister(Factor);

            Assert.AreEqual(3, NumberOfPrimes);
        }
예제 #7
0
        public int ApplyFirstMethod(int number)
        {
            var isPrime          = new IsPrime();
            var result           = new bool();
            var smallPrimeNumber = new int();

            for (int i = number - 1; i >= 0; i--)
            {
                isPrime.CheckIsPrimeNumber(i, result);
                if (result == true)
                {
                    smallPrimeNumber = i;
                    break;
                }
            }
            return(smallPrimeNumber);
        }
예제 #8
0
        public int ApplySecondMethod(int number, int smallPrimeNumber)
        {
            var isPrime = new IsPrime();
            var result  = new bool();

            int[] primeNumbers = new int[number];
            int   index        = 0;

            for (int i = 1; i < number; i++)
            {
                isPrime.CheckIsPrimeNumber(i, result);
                if (result == true)
                {
                    primeNumbers[index] = i;
                    index++;
                }
            }
            smallPrimeNumber = primeNumbers[primeNumbers.Length - 1];
            return(smallPrimeNumber);
        }
예제 #9
0
        static void Main(string[] args)
        {
            var number       = 10;
            var result       = new bool();
            var result1      = new int();
            var result2      = new int();
            var isPrime      = new IsPrime();//publisher
            var firstMethod  = new FirstMethod();
            var secondMethod = new SecondMethod();

            isPrime.IsPrimeNumber += firstMethod.OnIsPrimeNumber;
            isPrime.IsPrimeNumber += secondMethod.OnIsPrimeNumber;

            isPrime.CheckIsPrimeNumber(number, result);
            System.Console.WriteLine(number + " is prime number: " + result);
            result1 = firstMethod.ApplyFirstMethod(number);
            System.Console.WriteLine("[First method]: the biggest prime number smaller then " + number + " is: " + result1);

            result2 = secondMethod.ApplySecondMethod(number, result2);
            System.Console.WriteLine("[Second method]: the biggest prime number smaller then " + number + " is: " + result2);
        }
예제 #10
0
        /// <summary>
        /// Determines the numbers primes
        /// </summary>
        public static void PrimeNumberSeq()
        {
            while (true)
            {
                string  value  = Console.ReadLine();
                IsPrime number = IsPrimeNumber(value);

                //break if blank space
                if (number == IsPrime.BLANK_SPACE)
                {
                    break;
                }

                if (number == IsPrime.Prime)
                {
                    Console.WriteLine("The number {0} is prime", value);
                }
                else if (number == IsPrime.NO_PRIME)
                {
                    Console.WriteLine("The number {0} is not prime", value);
                }
            }
        }
예제 #11
0
 public void FailWithNumberTextValue()
 {
     IsPrime result = Week4.IsPrimeNumber("pepe");
 }
예제 #12
0
        public void WorkForBlankSpace()
        {
            IsPrime result = Week4.IsPrimeNumber("");

            Assert.AreEqual(result, IsPrime.BLANK_SPACE);
        }
예제 #13
0
        public void WorkForNonPrimeNumbers()
        {
            IsPrime result = Week4.IsPrimeNumber("10");

            Assert.AreEqual(result, IsPrime.NO_PRIME);
        }
예제 #14
0
        static void Main(string[] args)
        {
            // StringProblems
            //Test calls for Reverse string
            string input = "jacob";

            Console.WriteLine(input + "<=>" + new string(SimpleProblem.ReverseString(input.ToCharArray())));
            input = "jake";
            Console.WriteLine(input + "<=>" + new string(SimpleProblem.ReverseString(input.ToCharArray())));
            input = "";
            Console.WriteLine(input + "<=>" + new string(SimpleProblem.ReverseString(input.ToCharArray())));
            input = "jdshjdh@#$%^&)";
            Console.WriteLine(input + "<=>" + new string(SimpleProblem.ReverseString(input.ToCharArray())));

            ReplaceSpaces.TestReplaceSpacesInplace();
            Anagrams.TestIsAnagramAlgo();
            StringRotation.TestIsThisRotatedString();
            RemoveDuplicates.TestRemoveDuplicatesFromString();
            StringToLongConverter.TestStringToLong();
            RegexMatching.TestMatch();
            SumOfTwoNumbersInArray.TestSumOfTwoNumbersInArray();
            SumOfThreeNumbersInArray.TestSumOfThreeNumbersInArray();
            PairInSortedArrayClosestToAParticularValue.TestPairInSortedArrayClosestToAParticularValue();
            PalindromeInStringPermutation.TestPalindromeInStringPermutation();
            EditDistanceBetweenStrings.TestEditDistanceBetweenStrings();
            AnagramIsPalindrome.TestAnagramIsPalindrome();
            GreatestPalindrome.TestGreatestPalindrome();
            ReverseStringWithoutVowels.TestReverseStringWithoutVowels();
            LongestSubstringWithKDistinctChars.TestLongestSubstringWithKDistinctChars();
            // Pattern Matching
            NativePatternMatching.TestNativePatternMatching();
            KMPPatternMatching.TestKMPPatternMatching();
            BoyerMoorePatternMatching.TestPatternMatching();
            RabinKarp.TestRabinKarp();

            //Console.ReadLine();

            //Array Problems
            ArrayOfNumsIncrement.TestIncrementArrayOfNumbers();
            MajorityElement.TestFindMajorityElement();
            Merge2SortedArrays.TestMergeSortedArrays();
            MaxDistanceInArray.TestMaxDistanceInArray();
            MovingAverage.TestMovingAverage();
            TotalAverage.TestTotalAverage();
            ArrayWithGreaterElementToRight.TestArrayWithGreaterElementToRight();
            WaterCollectedInPuddleShownByHistogram.TestWaterCollectedInPuddleShownByHistogram();
            CountOfPairsWhichSumUpToGivenSum.TestCountOfPairsWhichSumUpToGivenSum();
            //Median.TestGetMedianOf2SortedArray();

            // Sorting Problems
            SelectionSort.TestSorting();
            BubbleSort.TestSorting();
            InsertionSort.TestSorting();
            ShellSort.TestSorting();
            MergeSort.TestMergeSort();
            QuickSort.TestQuickSort();
            HeapSortTester.TestHeapSort();
            CountingSort.TestSorting();
            RadixSort.TestRadixSort();
            DutchNationalFlag.TestDutchNationalFlag();
            SortedSquares.TestSortedSquares();

            // Matrix Problem
            Rotate_Matrix_90_degree.TestRotateMatrix();
            Matrix_Column_Rows_0.TestMakeRowColZero1();
            Matrix_Column_Rows_0.TestMakeRowColZero2();
            RotateMatrix180.TestRotateMatrix180();
            SumOfMatrixElementsFormedByRectangleWithCoordinates.TestSumOfMatrixElements();
            SortedArrayFromSortedMatrix.TestSortedArrayFromSortedMatrix();
            SearchWordInMatrix.TestSearchWordInMatrix();
            MaxOnesInRow.TestMaxOnesInRow();
            MatrixAsTriangle.TestMatrixAsTriangle();
            MinRangeInMatrix.TestMinRangeInMatrix();
            PrintMatrixAsSnake.TestPrintMatrixAsSnake();
            PrintMatrixInSpiral.TestPrintMatrixInSpiral();
            MaxSqAreaInBinaryMatrix.TestMaxRectAreaInBinaryMatrix();
            TicTacToeWinner.TestTicTacToeWinner();
            WaterfallCreation.TestWaterfallCreation();

            // Linked list Problems
            DeleteLinkedListNode.TestDeleteFirstNode();
            DeleteDuplicatesFromLinkedList.TestDeleteDuplicates();
            NthLastElementOfLinkedList.TestNthLastNodeOfLinkedList();
            DeleteNodeWithDirectReference.TestDeleteNode();
            AddNumbers.TestAddNumbersRepresentedByLinkedList();
            CopyLinkedListWithRandomNode.TestGetCopiedLinkedListWithRandomNode();
            CommonElementInTwoLinkedList.TestCommonElement();
            ReverseAdjacentNodesInLinkedList.TestReverseAdjacentNodes();
            MergeSortedLinkedList.TestMerge();
            CycleInLinkedList.TestStartOfCycleInLinkedList();
            MedianForCircularLinkedList.TestGetMedian();
            ReverseLinkedList.TestReverseLinkedList();
            SortedCircularLinkedList.TestCircularLinkedList();

            // stack and queue problem
            ThreeStackWithOneArray.TestThreeStackWithOneArray();
            StackWithMinElement.TestStackWithMinElement();
            StackOfPlates.TestStackOfPlates();
            SortAStack.TestSortAStackAscending();
            WellFormedExpression.TestWellFormedExpression();
            QueueVia2Stack.TestQueueVia2Stack();
            LRUCache.TestLRUCache();
            EvaluatePrefixNotation.TestGetPrefixNotationResult();
            EvaluateInflixNotation.TestGetInflixNotationResults();
            EvaluatePostfixNotation.TestGetPostfixNotationResult();
            TestCircularQueue.TestCircularQueueWithDifferentCases();
            LargestAreaInHistogram.TestLargestAreaInHistogram();
            TextEditerWithUndo.TestTextEditerWithUndo();

            //Recursion Problem
            TowerOfHanoi.TestTowerOfHanoi();
            MaxSumOfConsecutiveNums.TestMaxSumOfConsecutiveNums();

            // Back tracking problems
            Sudoku.TestSudokuSolver();
            HamiltonianCycle.TestHamiltonianCycle();
            GraphColoringWithMColors.TestGraphColoringWithMColors();
            MakeLargestIsland.TestMakeLargestIsland();

            //Misc Problem
            MinNumOfCoins.TestMinNumOfCoins();
            IsPrime.TestCheckPrime();
            SquareRoot.TestCalculateSquareRoot();
            CreditCardCheck.TestLuhnAlgo();
            ExcelFirstRowConversion.TestCovertExcelColumnToLong();
            Skyline.TestSkyline();
            SumOfSquaresWithoutMultiplication.TestSumOfSquares();
            MergeIntervals.TestMergeIntervals();
            WidthOfCalendar.TestWidthOfCalendar();
            JosephusProblem.TestJosephusProblem();

            // Permutation and Combination problem
            ShuffleAList.TestFisherYatesAlgo();
            CombinationsOfBinaryString.TestCombinationsOfBinaryString();
            AllCombinationsOfString.TestAllCombinationsOfString();
            AllPermutationsOfString.TestAllPermutationsOfString();
            PhoneNumberToWords.TestPhoneNumberToWords();
            AllNumbersInRangeWithDifferentDigits.TestAllNumbersInRangeWithDifferentDigits();
            DivideSetIntoTwoEqualSetsWithMinSumDiff.TestDivideSetIntoTwoEqualSetsWithMinSumDiff();
            PowerSet.TestPowerSet();
            AllCombinationsOfParenthesis.TestAllCombinationsOfParenthesis();
            GoodDiceRoll.TestGoodDiceRoll();
            PermutationsOfValidTime.TestPermutationsOfValidTime();

            // Tree Problems
            TreeFromExpression.TestCreateTreeFromExpression();
            TestBinarySearchTree.TestDifferentOperationsOnBST();
            AncestorOfTwoNodesInBST.TestAncestorOfTwoNodesInBST();
            CheckBTisBST.TestCheckBTisBST();
            MaxSumOnTreeBranch.TestMaxSum();
            WalkTheTree.TestWalkTheTree();
            SkewedBSTToCompleteBST.TestConvertSkewedBSTToCompleteBST();
            CheckIfTheTreeIsBalanced.TestIsTreeBalanced();
            LinkedListOfTreeNodesAtEachDepth.TestCreateLinkedListOfTreeNodesAtEachDepth();
            PrintBinaryTreeNodeAtEachLevel.TestPrintBinaryTreeNodeAtEachLevel();
            PrintBinaryTreeNodeAtEachLevelSpirally.TestPrintBinaryTreeNodeAtEachLevelSpirally();
            TreeSubtreeOfAnother.TestMatchTree();
            AncestorOfTwoNodesInBT.TestGetAncestorOfTwoNodesInBT();
            AncestorOfMultiNodesInBT.TestAncestorOfMultiNodesInBT();
            LinkedListFromLeavesOfBT.TestLinkedListFromLeavesOfBT();
            ExteriorOfBT.TestPrintExteriorOfBT();
            DepthOfTree.TestGetDepthOfTree();
            TreeToColumns.TestTreeToColumns();
            KthSmallestElementFromBST.TestKthSmallestElementFromBST();
            MakeBSTFromPreOrder.TestMakeBSTFromPreOrder();
            MirrorATree.TestMirrorATree();
            CloneABTWithRandPointer.TestCloneABTWithRandPointer();
            TreeWithInorderAndPreorder.TestTreeWithInorderAndPreorder();
            TreeWithInorderAndPostorder.TestTreeWithInorderAndPostorder();
            TreePathSumsToValue.TestTreePathSumsToValue();
            AllPathInNArayTree.TestAllPathInNArayTree();
            SerializeDeserializeBinaryTree.TestSerializeDeserializeBinaryTree();
            SerializeDeserializeAnNaryTree.TestSerializeDeserializeAnNaryTree();
            AncestorOfTwoNodesInNaryTree.TestAncestorOfTwoNodesInNaryTree();
            AbsOfMaxAndSecondMaxDepthInBT.TestGetAbsOfMaxAndSecondMaxDepthInBT();

            // Trie problems
            CreateAndSearchSimpleTrie.TestCreateAndSearchSimpleTrie();
            // ToDo: have a problem of suffix trees
            ShortestPrefix.TestGetShortestPrefixNotPresentInStringSet();

            // Dynamic Programming problems
            LongestCommonSubsequence.TestGetLongestCommonSubsequence();
            LongestPalindromeSubString.TestGetLongestPalindromeSubString();
            LongestPalindromicSubsequence.TestGetLongestPalindromicSubsequence();
            MaximumAs.TestGetMaximumAs();
            MinNumberOfJumps.TestGetMinimumNumberOfJumps();
            LongestCommonSubString.TestGetLongestCommonSubString();
            KnapSackProblem.TestGetTheMaximumValueWithLimitedWeight();
            TreeCuttingProblem.TestGetTreeCuttingToMaximizeProfits();
            WordBreaking.TestBreakTheWords();
            DistanceOfWords.TestDistanceOfWords();
            LongestIncreasingSubSequence.TestLongestIncreasingSubSequence();
            MinCostPath.TestMinCostPath();
            DifferentWaysForCoinChange.TestDifferentWaysForCoinChange();
            MatrixMultiplication.TestMatrixMultiplication();
            BinomialCoefficient.TestBinomialCoefficient();
            BoxStacking.TestBoxStacking();
            WordWrapping.TestWordWrapping();
            MaxSubMatrixWithAllOnes.TestMaxSubMatrixWithAllOnes();
            LongestSubStringWithEqualSum.TestLongestSubStringWithEqualSum();
            PartitionArrayIntoEqualSumSets.TestPartitionArrayIntoEqualSumSets();
            MaxSumRectangle.TestMaxSumRectangle();
            RegularExpressionMatch.TestRegularExpressionMatch();
            NumRepresentedByPerfectSquares.TestNumRepresentedByPerfectSquares();
            LongestCommonSubsequenceInSameString.TestLongestCommonSubsequenceInSameString();
            StringDecodeAsAlphabets.TestStringDecodeAsAlphabets();
            BalloonBursting.TestBalloonBursting();
            TravellingSalesmanProblem.TestTravellingSalesmanProblem();
            MaxSumWithoutAdjacentElements.TestMaxSumWithoutAdjacentElements();
            MaxPathThroughMatrix.TestMaxPathThroughMatrix();
            BrickLaying.TestBrickLaying();
            JobSchedullingWithConstraints.TestJobSchedullingWithConstraints();
            EggDropMinTrials.TestEggDropMinTrials();

            // Graph Problems
            ShortestPath.TestGetShortestPathBetween2Vertex();
            CycleInDirectedGraph.TestIsCycleInDirectedGraph();
            CycleInUnDirectedGraph.TestIsCycleInUnDirectedGraph();
            SolveAMaze.TestSolveAMaze();
            AllPathsGivenStartEndVertex.TestGetAllPathsInGraphFromStartVertexToEndVertex();
            AllPaths.TestGetAllPathsInGraphFromStartVertex();
            ColorVertices.TestColorVerticesWithDifferentColor();
            CheckBipartiteGraph.TestCheckBipartiteGraph();
            TransformOneWordToAnother.TestGetTransformation();
            ConstraintsVerification.TestConstraintsVerification();
            ExtendedContactsInSocialNetwork.TestComputeExtendedContacts();
            CourseScheduling.TestCourseScheduling();
            SnakeAndLadder.TestSnakeAndLadder();
            IsGraphATree.TestIsGraphATree();
            ReverseGraph.TestReverseGraph();
            StronglyConnectedGraph.TestStronglyConnectedGraph();
            ConnectedComponents.TestConnectedComponents();
            ContinentalDivide.TestContinentalDivide();
            CloneGraph.TestCloneGraph();
            Wordament.TestWordament();
            // ShortestPathAlgo
            FloydWarshall.TestFloydWarshall();
            DijkstraAlgorithm.TestDijkstraAlgorithm();
            BellmanFord.TestBellmanFord();
            TravelFromLeftToRightInMatrix.TestTravelFromLeftToRightInMatrix();
            HeuristicSearch.TestHeuristicSearch();
            AStar.TestAStar();
            ShortestPathWhenObstaclesRemoved.TestShortestPathWhenObstaclesRemoved();
            ShortestDistanceFromRoomsToGates.TestShortestDistanceFromRoomsToGates();
            //MaxFlow
            FordFulkersonEdmondKarp.TestFordFulkersonEdmondKarp();
            MinCut.TestMinCut();
            MaximumBipartiteMatching.TestMaximumBipartiteMatching();
            //Minimum Spanning Tree
            KruskalAlgorithm.TestKruskalAlgorithm();
            PrimsAlgorithm.TestPrimsAlgorithm();


            //Heap problems
            BasicMaxHeap.TestMaxHeap();
            BasicMinHeap.TestMinHeap();
            TestMinHeapMap.DoTest();
            TestPriorityQueue.Run();
            MedianForAStreamOfNumbers.TestMedianForAStreamOfNumbers();

            //DisjointSets
            TestingDisjointSet.Run();
            //TestWeightedDisjointSetsWithPathCompression.Run(); // this runs slow, hence commenting it

            //Geometry
            ClosestPairOfPoints.TestClosestPairOfPoints();
            RectangleIntersection.TestRectangleIntersection();
            LineSegmentIntersection.TestLineSegmentIntersection();
            ConvexHull.TestConvexHull();
            KClosestPointToOrigin.TestKClosestPointToOrigin();

            //Greedy Algorithm
            HuffmanCoding.TestHuffmanCoding();

            //Randomized Algorithm
            RandomGeneration.TestRandomGeneration();

            // Bit Algorithms
            IntHaveOppositeSigns.TestIntHaveOppositeSigns();
            Parity.TestParity();

            //Math Problem
            ZerosInFactorial.TestZerosInFactorial();
            GetAllPrimeFactors.TestGetAllPrimeFactors();
            NumberOfFactors.TestNumberOfFactors();
            AllFactors.TestAllFactors();
            MultiplyLongNumbers.TestMultiplyLongNumbers();
            NextLargestPermutation.TestNextLargestPermutation();
            AllPrimesTillN.TestAllPrimesTillN();
            PascalsTriangle.TestPascalsTriangle();
            SubtractLongNumbers.TestSubtractLongNumbers();

            //Search problems
            SearchInSortedRotatedArray.TestSearchInSortedRotatedArray();
            KClosestElementInArray.TestKClosestElementInArray();
            SearchInSortedMatrix.TestSearchInSortedMatrix();
            BinarySearchUnbounded.TestBinarySearchUnbounded();
            LinkedListSublistSearch.TestLinkedListSublistSearch();
            NoOfOccuranceInSortedArray.TestNoOfOccuranceInSortedArray();
            GetSmallestInSortedRotatedArray.TestGetSmallestInSortedRotatedArray();

            //Distributed algorithms
            KWayMerge.TestKWayMerge();


            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            string[] strings =
            {
                "(){}",
                ")"
            };

            foreach (var s in strings)
            {
                string results = BracketDelimiter.IsBalanced(s) ? "succes" : "niet oké";
                Debug.WriteLine(results);
            }

            var resultTot = PostfixCalculator.Calculate("12 10-2+25*10/");

            Console.WriteLine(resultTot);

            //BracketDelimiter.IsBalanced("(){}");

            //BracketDelimiter.IsBalanced("()");
            //BracketDelimiter.IsBalanced("((");

            //BracketDelimiter.IsBalanced("{()}");
            //BracketDelimiter.IsBalanced("{()");
            //BracketDelimiter.IsBalanced("''");

            ////var resultS =  BracketDelimiter.IsBalanced("<?<??>?>");
            //var resultSS = BracketDelimiter.IsBalanced("for(int i = 0; i< 100; i++){}");

            //Console.WriteLine(resultSS);
            Console.ReadLine();
            return;


            OddNumberPrinter.ExecuteEven(2);
            OddNumberPrinter.ExecuteOdd(3);



            var result = InterestCalculator.Calculate(2, 1, 5000);

            List <string> items = new List <string> {
                "a", "b", "c", "d", "e", "f", "g"
            };

            Permutation.Permutations(items);
            Console.WriteLine(Permutation.GetPermutationCount);

            //Printer.PrintAsc();
            //Console.WriteLine(NaturalCounter.Execute(5));
            //DigitSeperator.Execute(255);
            //Console.WriteLine(DigitCounter.Execute(12345));
            //OddNumberPrinter.Execute(20);
            ItterativeIndex ittIdIndex = new ItterativeIndex();

            int value = ittIdIndex.IndexOf(new int[] { 1, 2, 3, 4, 5 }, 5, 0);


            IsPrime.Execute(37, 37 / 2);
            IsPalindrome.Execute("ABBA");
            Console.WriteLine(
                FactorialCalculator.Execute(8));
            //ForLoopProblem.Problem();

            char startPeg   = 'A';  // start tower in output
            char endPeg     = 'C';  // end tower in output
            char tempPeg    = 'B';  // temporary tower in output
            int  totalDisks = 1200; // number of disks

            //TowersOfHanoi.Solve(totalDisks, startPeg, endPeg, tempPeg);


            int[,] random = new int[, ]
            {
                { 200, 400 },
                { 2000, 4176 },
                { 20000, 40000 },
                { 50000, 50000 }
            };

            //var c = _2DArraySum.GetHighestSum(random);

            var getHighestSummedArray = new _2DArraySumAsClass <int[, ]>();

            Console.WriteLine("Highest value" + getHighestSummedArray.GetHighestSum(random));


            //Create linked list
            LinkedListExercise linkedListExercise = new LinkedListExercise();

            //Add data
            linkedListExercise.Employees.AddLast(new Employee("Bob", 5));
            linkedListExercise.Employees.AddLast(new Employee("Alice", 5000));

            //ShallowCopy with IClonable
            var shallowCopy = linkedListExercise.ShallowCopy();
            //Shallow copy with Collection<T>() ctor
            var shallowCopyCollection = linkedListExercise.ShallowCopyCollection();
            //Deep copy
            var deepCopy = linkedListExercise.DeepCopy();


            //var bucketSort = new BucketSort();
            //bucketSort.Execute(new[] { 8, 2, 122, 1, 99, 3, 4, 2 });

            //BubbleSort bubbleSort = new BubbleSort();
            //var res = bubbleSort.Execute(new int[]{8,2, 122, 1});

            //var x = new Solution3();
            //x.Slow(100);
            //x.Fast(100);

            //var binarySearch = new BinarySearch();
            //var array = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            //int pos = binarySearch.Execute(array, 10);

            //var input = "8,1,6;3,5,7;4,9,2";
            //var array = (from x in input.Split(',', ';') select int.Parse(x)).ToArray();
            //var magic = new MagicSquare();
            //magic.Execute(3);

            //magic.ExecuteCorrect(3);
            //MagicSquare.RunMagicSquare(3);


            //Binary Search recurisve.
            //int[] testArray = { 1,2,3,4,5,6,7,8,9,10,11,12};
            //var length = testArray.Length;
            //var searchFor = 10;

            //Console.WriteLine(BinarySearch.RecursiveV2(searchFor, testArray, 0, length));
            //Console.WriteLine($"Self made {BinarySearch.BinarySearchRecursiveSelf(testArray, 0, length, searchFor)}");


            //Console.WriteLine(
            //    ADS.Core.Lesson_2.Converter.DecimalToBin(10));

            //Console.WriteLine("Bin 2 dec " + ADS.Core.Lesson_2.Converter.Bin2dec(1100));
            //Console.WriteLine(ADS.Core.Lesson_2.Converter.BinToDecimal("10101"));


            //Console.WriteLine(Palindrome.IsPalindrome("racecar"));

            // Console.WriteLine(ReverseString.ExecuteV1("ban"));
            // Console.WriteLine(ReverseString.Execute("ban"));

            // ArrayCombiner arrayCombiner = new ArrayCombiner();
            //var x = arrayCombiner.Execute(new int[] { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 },
            //     new int[] { 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 });

            //ArrayListCombiner arrayListCombiner = new ArrayListCombiner();

            // var y = arrayListCombiner.Merge(new List<int> { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 },
            //    new List<int> { 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 });


            // Create first polynomial
            var polynomial1 = new Polynomial();

            polynomial1.Add(new Term(1, 2));
            polynomial1.Add(new Term(2, 2));
            polynomial1.Add(new Term(3, 0));


            // Create second polynomial
            var polynomial2 = new Polynomial();

            polynomial2.Add(new Term(-1, 3));
            polynomial2.Add(new Term(1, 1));
            polynomial2.Add(new Term(1, 2));

            Stopwatch x = new Stopwatch();

            x.Start();
            Polynomial polyX        = polynomial1.SumWorking(polynomial2);
            var        termsWorking = polyX.GetAllTerms();

            x.Stop();
            Console.WriteLine(x.ElapsedTicks + "TICKS");
            x.Reset();

            x.Start();

            Polynomial polyOptimized = polynomial1.OptimizedAlgorithm(polynomial2);
            var        optimzedTerms = polyX.GetAllTerms();

            x.Stop();
            Console.WriteLine(x.ElapsedTicks + "TICKS");
            x.Reset();

            // Determine the sum
            Polynomial polynomialSum = polynomial1.Sum(polynomial2);
            var        terms         = polynomialSum.GetAllTerms();

            for (int i = 0; i < polynomialSum.GetAllTerms().Count; i++)
            {
                Console.Write($"{terms[i].toString()}\t");
            }

            //TowersOfHanoi.Solve(64);
            //TowersOfHanoi.TowerHanoi(3);
            //-> coeff = 1 - X^ > ex3
            //2X^3
            //-5^0

            //var c = BinarySearch.binarySearchFloris(new int[] { 1,2,3,4,5,6,7,8,9,10 }, 2);

            Hangman hangman = new Hangman();

            hangman.ChooseWord();

            bool val = true;

            while (val)
            {
                string input = Console.ReadLine();
                hangman.GuessWord(input);

                if (input == "exit")
                {
                    val = false;
                }
            }

            int[] arr1 = new int[] { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 };
            int[] arr2 = new int[] { 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 };

            int[] execute = ArrayCombiner.combineArray(arr2, arr1);

            //var intList = new ArrayList();
            //intList[1] as int? = 2;

            var res12 = ArrayListCombiner.Merge(new ArrayList()
            {
                1, 2, 3, 4
            }, new ArrayList()
            {
                1, 2, 3, 4
            });

            int max = MaxRec.Execute(new int[] { 1, 2, 3, 4, 1204 });


            Console.WriteLine();

            //Console.WriteLine(Converter.BinToDecimal("1011"));
            Console.ReadLine();
        }
예제 #16
0
 public void FailWithNumberLessThanZero()
 {
     IsPrime result = Week4.IsPrimeNumber("-1");
 }
예제 #17
0
        public void WorkForPrimeNumbers()
        {
            IsPrime result = Week4.IsPrimeNumber("2");

            Assert.AreEqual(result, IsPrime.Prime);
        }