public static long LargestPandigitalFormedWithMultiples() { var pandigitals = new List <long>(); for (long i = 1; i <= 9876; i++) { if (PandigitalNumber.IsPandigitalWithoutZero(i)) { var pandigitalNumber = i; for (int j = 2; j < 10; j++) { pandigitalNumber = pandigitalNumber.JoinWith(i * j); if (pandigitalNumber > 987_654_321 || !PandigitalNumber.IsPandigitalWithoutZero(pandigitalNumber)) { break; } if (pandigitalNumber >= 123_456_789) { pandigitals.Add(pandigitalNumber); break; } } } } return(pandigitals.Max()); }
public static long ProductsSum() { var pandigitalProducts = new List <long>(); long sum = 0; for (long a = 2; a <= 98; a++) { if (PandigitalNumber.IsPandigitalWithoutZero(a)) { var bInit = a < 10 ? 1234 : 123; var bThreshold = a < 10 ? 9876 : 987; for (long b = bInit; b <= bThreshold; b++) { var ab = a.JoinWith(b); if (PandigitalNumber.IsPandigitalWithoutZero(ab)) { var product = a * b; if (PandigitalNumber.IsPandigitalWithoutZero(product.JoinWith(ab)) && !pandigitalProducts.Contains(product)) { pandigitalProducts.Add(product); sum += product; } } } } } return(sum); }