void PESolution.solve() { int length = 1000; int[] fibMinusOne = new int[length]; int[] fib = new int[length]; fibMinusOne[0] = 1; fib[0] = 1; int fibIndex = 2; while (fib[length - 1] == 0) { int carryover = 0; int[] tempFib = new int[length]; fib.CopyTo(tempFib, 0); for (int i = 0; i < length; i++) { int newNumber = fibMinusOne[i] + tempFib[i]; fib[i] = PELibrary.getOnes(newNumber) + carryover; carryover = PELibrary.getTens(newNumber); } tempFib.CopyTo(fibMinusOne, 0); fibIndex++; } Console.WriteLine("Answer is {0}", fibIndex); }
void PESolution.solve() { int[] digits = new int[159]; digits[0] = 1; int targetNumber = 100; for (int i = 1; i <= targetNumber; i++) { int[] carryover = new int[digits.Length + 2]; for (int j = 0; j < digits.Length; j++) { int newNumber = i * digits[j]; carryover[j + 1] += PELibrary.getTens(newNumber) + PELibrary.getTens(PELibrary.getOnes(newNumber) + carryover[j]); carryover[j + 2] += PELibrary.getHundreds(newNumber); digits[j] = PELibrary.getOnes(PELibrary.getOnes(newNumber) + carryover[j]); } } int sum = 0; for (int i = 0; i < digits.Length; i++) { sum += digits[i]; } Console.WriteLine("Answer is {0}", sum); }
void PESolution.solve() { int aMax = 0; int bMax = 0; int nMax = 0; int[] primes = PELibrary.getPrimesUpToLimit(111000); // Brute Force for (int a = -1000; a <= 1000; a++) { for (int b = -1000; b <= 1000; b++) { int n = 0; while (isPrime(n * n + a * n + b, primes)) { n++; } if (n > nMax) { aMax = a; bMax = b; nMax = n; } } } int answer = aMax * bMax; Console.WriteLine("Answer is {0}", answer); }
private static int numberOfLetters(int n) { int ones = PELibrary.getOnes(n); int tens = PELibrary.getTens(n); int hundreds = PELibrary.getHundreds(n); int thousands = PELibrary.getThousands(n); int count = 0; // Add for x1-99 if (tens == 0) { if (ones != 0) { count += cardinalLength[ones]; } } else if (tens == 1) { count += cardinalLength[tens * 10 + ones]; } else { count += cardinalLength[10 * tens]; if (ones > 0) { count += cardinalLength[ones]; } } // Add for x100-999 if (hundreds != 0) { count += cardinalLength[hundreds] + cardinalLength[100]; if (ones == 0 && tens == 0) { count -= "and".Length; } } // Add for x1000+ if (thousands != 0) { count += cardinalLength[thousands] + cardinalLength[1000]; } return(count); }