public void TestGetDigitCounts() { long value = 99987654321; NumericPermutation test = new NumericPermutation(numbericValue: value); Dictionary <int, int> digitCounts = test.GetDigitCounts(); Assert.AreEqual(9, digitCounts.Keys.Count); Assert.AreEqual(3, digitCounts[9]); }
public void TestEquals() { long value = 99977531; NumericPermutation firstVal = new NumericPermutation(numbericValue: value); long otherValue = 13579799; NumericPermutation secondVal = new NumericPermutation(numbericValue: otherValue); long lastValue = 12345678; NumericPermutation thirdVal = new NumericPermutation(numbericValue: lastValue); Assert.IsFalse(firstVal.Equals(obj: null)); Assert.IsFalse(firstVal.Equals(obj: otherValue)); Assert.IsTrue(firstVal.Equals(secondVal)); Assert.IsFalse(firstVal.Equals(thirdVal)); }
public static long FindCubicPermutationsNew(int numPermutations) { List <long> cubicNumbersList = new List <long>(); int maxNumPermutations = 1; long valueWithMaxPermutations = 1; int numValuesChecked = 0; for (long i = 1; i < 12000; i++) { long currCubicNum = i * i * i; cubicNumbersList.Add(item: currCubicNum); } var keys = cubicNumbersList.ToArray(); for (int i = 0; i < keys.Length - 1; i++) { int currNumPermutations = 1; for (int j = i + 1; j < keys.Length; j++) { NumericPermutation firstNum = new NumericPermutation(keys[i]); NumericPermutation secondNum = new NumericPermutation(keys[j]); if (firstNum.Equals(secondNum)) { currNumPermutations++; } } if (currNumPermutations > maxNumPermutations) { maxNumPermutations = currNumPermutations; valueWithMaxPermutations = keys[i]; } //Debug.WriteLine("{0} has {1} cubic permutations. So far, {2} had the most cubic permutations with {3}", // keys[i], currNumPermutations, valueWithMaxPermutations, maxNumPermutations); if (currNumPermutations == numPermutations) { return(keys[i]); } } throw new NotImplementedException(); }