Exemple #1
0
        public static IEnumerable <long> Get()
        {
            var pandigitals =
                SetUtils.Permutations(Enumerable.Range(0, 10).Select(x => (long)x))
                .Select(d => d.Reverse())
                .Where(digits => digits.First() != 0);

            return(pandigitals.Where(HasSubstringDivisibility).Select(x => x.DigitsToNumber()));
        }
Exemple #2
0
        public static IEnumerable <string> Main()
        {
            var fourDigitPrimes = new HashSet <long>(PrimeUtils.Primes
                                                     .SkipWhile(x => x.ToString().Length < 4)
                                                     .TakeWhile(x => x.ToString().Length == 4));

            while (fourDigitPrimes.Any())
            {
                var prime             = fourDigitPrimes.First();
                var permutations      = SetUtils.Permutations(MiscUtils.GetDigits(prime)).Select(x => (long)x.DigitsToNumber()).Where(x => x > 1000);
                var primePermutations = fourDigitPrimes.Intersect(permutations).ToArray();

                if (primePermutations.Length >= 3)
                {
                    var threes = primePermutations.Choose(3).ToArray();
                    foreach (var special in threes.Where(HaveEqualDifference))
                    {
                        yield return(string.Join("", special.OrderBy(x => x)));
                    }
                }

                fourDigitPrimes.ExceptWith(primePermutations);
            }
        }
Exemple #3
0
 public static IEnumerable <int[]> PandigitalNumbers(int pandigital)
 {
     return(SetUtils.Permutations(Enumerable.Range(1, pandigital)));
 }