예제 #1
0
파일: Problem049.cs 프로젝트: ajdust/euler
        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())));
        }
예제 #2
0
        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());
        }
예제 #3
0
 private IEnumerable <IList <char> > PandigitalPermutations()
 {
     return(Combinatorics.PermuteForward(new [] { '1', '2', '3', '4', '5', '6', '7', '8', '9' }));
 }