コード例 #1
0
 public static BigInteger NChooseR(int n, int r)
 {
     if (r > n)
     {
         throw new ArgumentException("R cannot be greater than N");
     }
     return((EulerMath.Factorial(n)) / (EulerMath.Factorial(r) * (EulerMath.Factorial(n - r))));
 }
コード例 #2
0
ファイル: Problem34.cs プロジェクト: asciamanna/ProjectEuler
        long CalculateFactorialSumOfDigits(int i)
        {
            BigInteger sum = 0;

            foreach (var digit in i.ToString())
            {
                sum += EulerMath.Factorial(long.Parse(digit.ToString()));
            }
            return(long.Parse(sum.ToString()));
        }
コード例 #3
0
ファイル: Problem20.cs プロジェクト: asciamanna/ProjectEuler
        public override long Solve()
        {
            var stringFactorial = EulerMath.Factorial(number).ToString();
            var listOfInts      = new List <int>();

            foreach (var digit in stringFactorial)
            {
                listOfInts.Add(Int32.Parse(digit.ToString()));
            }

            return(listOfInts.Sum());
        }
コード例 #4
0
ファイル: Problem15.cs プロジェクト: asciamanna/ProjectEuler
        public override long Solve()
        {
            //starting top left and moving to bottom right can only
            //go east (e) or south(s).  to travel to the bottom right
            //you need to travel exactly N e and N s for a N x N grid.
            //Therefore, the total number of routes is all of the permutations
            //N e and N s
            //N! / (A! * B!) where N = total numbers, with some number repeated A times and another number repeated B times.
            // 40! / (20! * 20!) because it would take 20 e routes and 20 s routes.
            var easternRoutes  = gridSize;
            var southernRoutes = gridSize;

            return((long)(EulerMath.Factorial(2 * gridSize) / (EulerMath.Factorial(easternRoutes) * EulerMath.Factorial(southernRoutes))));
        }
コード例 #5
0
ファイル: Problem24.cs プロジェクト: asciamanna/ProjectEuler
        public override long Solve()
        {
            int    N                 = numbers.Count;
            string permutation       = "";
            int    permutationToFind = 1000000 - 1;

            for (int i = 1; i < N; i++)
            {
                int location = (int)(permutationToFind / EulerMath.Factorial(N - i));
                permutationToFind = (int)(permutationToFind % EulerMath.Factorial(N - i));
                permutation       = permutation + numbers[location];
                numbers.RemoveAt(location);
                if (permutationToFind == 0)
                {
                    break;
                }
            }
            for (int i = numbers.Count - 1; i >= 0; i--)
            {
                permutation += numbers[i];
            }
            return(long.Parse(permutation));
        }
コード例 #6
0
 public Fraction(int numerator, int denominator)
 {
     this.numerator   = numerator;
     this.denominator = denominator;
     gcf = EulerMath.GreatestCommonFactor(numerator, denominator);
 }