public void GetAllPermutationsTest_WithFiveCharacters() { var stringPermutations = new StringPermutations(); var result = stringPermutations.GetAllPermutations("ABCDE"); Assert.AreEqual("ABCDE ABCED ABDCE ABDEC ABEDC ABECD ACBDE ACBED ACDBE ACDEB ACEDB ACEBD ADCBE ADCEB ADBCE ADBEC ADEBC ADECB AECDB AECBD AEDCB AEDBC AEBDC AEBCD BACDE BACED BADCE BADEC BAEDC BAECD BCADE BCAED BCDAE BCDEA BCEDA BCEAD BDCAE BDCEA BDACE BDAEC BDEAC BDECA BECDA BECAD BEDCA BEDAC BEADC BEACD CBADE CBAED CBDAE CBDEA CBEDA CBEAD CABDE CABED CADBE CADEB CAEDB CAEBD CDABE CDAEB CDBAE CDBEA CDEBA CDEAB CEADB CEABD CEDAB CEDBA CEBDA CEBAD DBCAE DBCEA DBACE DBAEC DBEAC DBECA DCBAE DCBEA DCABE DCAEB DCEAB DCEBA DACBE DACEB DABCE DABEC DAEBC DAECB DECAB DECBA DEACB DEABC DEBAC DEBCA EBCDA EBCAD EBDCA EBDAC EBADC EBACD ECBDA ECBAD ECDBA ECDAB ECADB ECABD EDCBA EDCAB EDBCA EDBAC EDABC EDACB EACDB EACBD EADCB EADBC EABDC EABCD", result); }
public void GetAllPermutationsTest_WithFourCharacters() { var stringPermutations = new StringPermutations(); var result = stringPermutations.GetAllPermutations("ABCD"); Assert.AreEqual("ABCD ABDC ACBD ACDB ADCB ADBC BACD BADC BCAD BCDA BDCA BDAC CBAD CBDA CABD CADB CDAB CDBA DBCA DBAC DCBA DCAB DACB DABC", result); }
public void GetAllPermutationsTest() { var stringPermutations = new StringPermutations(); var result = stringPermutations.GetAllPermutations("ABC"); Assert.AreEqual("ABC ACB BAC BCA CBA CAB", result); }
public double GetDivisiblePanDigitalNumberSum(string digits = "9876543210") { var results = StringPermutations.Permute(digits).Select(Convert.ToDouble) .Where(d => TestValue(d.ToString())).ToList(); return(results.Sum()); }
public void NullTest() { string s = null; var sp = new StringPermutations(); var result = sp.GetAllPermutations(s); Assert.Equal(new HashSet <String>(), result); }
public void StringPermutationsTest() { var input = new[] { "hat", "abc", "Zu6" }; var expected = new[] { "aht,ath,hat,hta,tah,tha", "abc,acb,bac,bca,cab,cba", "6Zu,6uZ,Z6u,Zu6,u6Z,uZ6" }; var prog = new StringPermutations(input); var result = prog.Run().ToList(); for (int i = 0; i < expected.Length; i++) { Assert.AreEqual(expected[i], result[i]); } }
//would probably work but not enough memory not to mention rather inefficient //public int GetLargestPandigitalPrimeBelowNumber(int number = 987654322) //{ // var primes = PrimeNumberHelper.GetPrimeNumbersBelowNumber(number); // Func<int, bool> isPandigital = i => // { // var digits = new Dictionary<string, int>(); // Enumerable.Range(1, 9) // .Select(e => new KeyValuePair<string, int>(e.ToString(), 0)) // .ToList().ForEach(e => digits.Add(e.Key, e.Value)); // i.ToString().ToCharArray().ToList().ForEach(c => digits[c.ToString()] = digits[c.ToString()] + 1); // return digits.All(d => d.Value < 2); // }; // return primes.Where(isPandigital).Max(); //} public int GetLargestPandigitalPrimeForDigits(string digits = "987654321") { var primes = new List <int>(); while (primes.Count == 0) { var results = StringPermutations.Permute(digits).Select(r => Convert.ToInt32(r)).ToList(); primes = results.Where(r => PrimeNumberHelper.IsPrime(r)).ToList(); digits = digits.Substring(1); } return(primes.Max()); }
public void GetPermutations() { var expected = new List <string>(); expected.AddRange(new string[] { "abc", "acb", "bac", "bca", "cba", "cab" }); var actual = StringPermutations.AllPermutations("abc"); // the sorting is only needed for the tests // to make both lists equal expected.Sort(); actual.Sort(); Assert.Equal(expected, actual); }
public void StringPermutationsTest() { var input = new[] {"hat", "abc", "Zu6"}; var expected = new[] {"aht,ath,hat,hta,tah,tha", "abc,acb,bac,bca,cab,cba", "6Zu,6uZ,Z6u,Zu6,u6Z,uZ6"}; var prog = new StringPermutations(input); var result = prog.Run().ToList(); for (int i = 0; i < expected.Length; i++) { Assert.AreEqual(expected[i], result[i]); } }
public static void Test(){ StringPermutations sp = new StringPermutations(); var res = sp.AreStringPermutes("rajiv","vijark"); Console.Write(res); }
public void GetUniqueChars() { Assert.Equal(4, StringPermutations.GetUniqueChars("holl")); }
public StringPermutations_AreEqualShould() { _sut = new StringPermutations(); }