On this article, we are going to study C# implementation of Brute-Power Algorithm.Brute-force search or exhaustive search, often known as generate and take a look at, is a really basic problem-solving method that consists of systematically enumerating all potential candidates for the answer and checking whether or not every candidate satisfies the issue’s assertion
utilizing System; utilizing System.Collections.Generic; utilizing System.Linq; utilizing System.Textual content; utilizing System.Threading.Duties; namespace BruteForceAlgorithm { class BruteForceAlgo { public delegate bool BruteForceTest(ref char[] testChars); public static bool BruteForce(string testChars, int startLength, int endLength, BruteForceTest testCallback) { for (int len = startLength; len <= endLength; ++len) { char[] chars = new char[len]; for (int i = 0; i < len; ++i) chars[i] = testChars[0]; if (testCallback(ref chars)) return true; for (int i1 = len - 1; i1 > -1; --i1) int i2 = 0; for (i2 = testChars.IndexOf(chars[i1]) + 1; i2 < testChars.Size; ++i2) chars[i1] = testChars[i2]; if (testCallback(ref chars)) return true; for (int i3 = i1 + 1; i3 < len; ++i3) if (chars[i3] != testChars[testChars.Length - 1]) i1 = len; goto outerBreak; outerBreak: if (i2 == testChars.Size) chars[i1] = testChars[0]; } return false; } static void Primary(string[] args) BruteForceTest testCallback = delegate(ref char[] testChars) var str = new string(testChars); return (str == "bbc"); ; bool end result = BruteForce("abcde", 1, 5, testCallback); Console.WriteLine(end result); } }
Output:
True
Thanks for visiting !!
© 2017, Csharp Star. All rights reserved.