public void Solve() { var n1 = new LargeNaturalNumber(556312); var n2 = new LargeNaturalNumber(556312); var n3 = n1.Add(n2); var test = Fib(2749); var rofl = test.Last9(); var rofl2 = test.First9(); var fibPrev = new LargeNaturalNumber(1); var fibPrevPrev = new LargeNaturalNumber(1); for (int i = 3; i < 10000000; i++) { var result = fibPrev.Add(fibPrevPrev); fibPrevPrev = fibPrev; fibPrev = result; var isPanLast = IsPanDigital(result.Last9()); var isPanFirst = IsPanDigital(result.First9()); if (isPanLast && isPanFirst) { Console.WriteLine("Pandigital in last and first is: " + i); var answer = result; } else if (isPanLast) { Console.WriteLine("Pandigital last is: " + i); } else if (isPanFirst) { Console.WriteLine("Pandigital first is: " + i); } } }
//Adds two large natural numbers together public LargeNaturalNumber Add(LargeNaturalNumber n2) { var newNumber = new LargeNaturalNumber(); newNumber.MaxCoefficent = Math.Max(MaxCoefficent, n2.MaxCoefficent); var carry = 0; for (int i = 0; i <= newNumber.MaxCoefficent; i++) { var ci = Coefficents[i] + n2.Coefficents[i] + carry; if (ci >= e) { newNumber.Coefficents[i] = ci - e; carry = 1; } else { newNumber.Coefficents[i] = ci; carry = 0; } } if (carry == 1) { newNumber.MaxCoefficent++; newNumber.Coefficents[newNumber.MaxCoefficent] = 1; } return newNumber; }