public string Solve() { var primes = new HashSet <int>(new Primes(10000).PrimeList().Where(x => x > 1000)); var matching = new List <int>(); foreach (var prime in primes) { if (matching.Contains(prime)) { continue; } var ps = Combinatorics.PermuteForward(prime.ToString().ToArray()) .Select(y => int.Parse(new string(y))) .Where(y => primes.Contains(y)) .ToList(); ps.Sort(); if (ps.Count() >= 3 && !ps.Contains(1487) && ps[1] + (ps[1] - ps[0]) == ps[2]) { matching.AddRange(ps); } } return(string.Join("", matching.OrderBy(x => x).Select(x => x.ToString()))); }
public string Solve() { var answer = Combinatorics.PermuteForward(_digits) .Where(x => x[0] != '0' && DivisibilityTest(x)) .Select(x => long.Parse(new string(x.ToArray()))) .Sum(); return(answer.ToString()); }
private IEnumerable <IList <char> > PandigitalPermutations() { return(Combinatorics.PermuteForward(new [] { '1', '2', '3', '4', '5', '6', '7', '8', '9' })); }