示例#1
0
        public void Run()
        {
            BigInteger sum = 0;

            //Ignore 1 and 2 as they are not sums
            for (int i = 3; i <= 1000000; i++)
            {
                if (i % 10000000 == 0)
                {
                    Console.WriteLine(i);
                }

                char[] characters = i.ToString()
                                    .ToCharArray();
                BigInteger interimResult = 0;
                foreach (char num in characters)
                {
                    interimResult += Factorials.GetFactorial(Int32.Parse(num.ToString()));
                }

                if (interimResult == i)
                {
                    Console.WriteLine(interimResult);
                    sum += interimResult;
                }
            }

            this.result = "The sum of factorions is:" + sum;
        }
    static void Main()
    {
        double e       = 1;
        int    counter = 1;
        // We would use it to know how many times to multiply "x" by itselft to get a proper power.
        int power = 1;

        // Ask a user to enter a number to use it as a power for e till the end of the app's runtime.
        Console.Write("Please enter a number to rise constant e to it's power: ");
        int x = int.Parse(Console.ReadLine());
        // A local variable to store "x's" powee
        int xPowered = x;

        // As soon as we are limited with maximum number integers and doubles can store, let's use 10 loops's precision.
        while (counter <= 10)
        {
            /* This loop would be executed once for every "counter's" value except the first one, where both "power" and "counter" equal to 1. When counter would be equal to 2, the loop would be executing once providing xPowered * x result stored in "xPowered", which is the second power of "x" - just what we need to the further calculations on the step. */
            while (power < counter)
            {
                xPowered *= x;
                ++power;
            }

            /* GetFactorial method returns an integer, so we need to cast in to double before use as divider for 1. */
            e += xPowered / (double)Factorials.GetFactorial(counter);
            ++counter;
        }

        Console.WriteLine($"The e constant provided by Math.E is:   {Math.Pow(Math.E, x)}");
        Console.WriteLine($"The e constant provided by thie app is: {e}");
    }
示例#3
0
文件: Program.cs 项目: matej-hron/POC
 private static void Test3()
 {
     WithMaterializer(m =>
     {
         var result = Factorials.Select(_ => _.ToString()).RunWith(LineSink(), m);
         Console.WriteLine(result.Result);
     });
 }
示例#4
0
        private static long Factorial(int n)
        {
            while (n >= Factorials.Count)
            {
                var lastValue = Factorials[Factorials.Count - 1];
                var newValue  = lastValue * Factorials.Count;
                Factorials.Add(newValue);
            }

            return(Factorials[n]);
        }
示例#5
0
文件: Program.cs 项目: matej-hron/POC
        private static async void Test4()
        {
            WithMaterializer(m =>
            {
                var x = Factorials
                        .ZipWith(GetSource, (num, idx) => $"{idx}! = {num}")
                        .Throttle(1, TimeSpan.FromSeconds(1), 1, ThrottleMode.Shaping)
                        .RunForeach(Console.WriteLine, m);

                x.Wait();
            });
        }
示例#6
0
文件: Program.cs 项目: matej-hron/POC
        private static void Test2()
        {
            WithMaterializer(materializer =>
            {
                var result =
                    Factorials
                    .Select(num => ByteString.FromString($"{num}\n"))
                    .RunWith(FileIO.ToFile(new FileInfo(@"c:\temp\factorials.txt")), materializer);

                Console.WriteLine(result.Result);
            });
        }
示例#7
0
        static void Main(string[] args)
        {
            // Main method is the only method that
            // can ’t be marked with async .
            // What we are doing here is just a way for us to simulate
            // async - friendly environment you usually have with
            // other .NET application types ( like web apps , win apps etc .)
            // Ignore main method , you can just focus on LetsSayUserClickedAButtonOnGuiMethod() as a
            // first method in call hierarchy .
            var t = Task.Run(() => Factorials.LetsSayUserClickedAButtonOnGuiMethod());

            Console.Read();
        }
    static void Main()
    {
        double e       = 1;
        int    counter = 1;

        // As soon as we are limited with maximum number integers and doubles can store, let's use 10 loops's precision.
        while (counter <= 10)
        {
            // GetFactorial method returns an integer, so we need to cast in to double before use as divider for 1.
            e += 1 / (double)Factorials.GetFactorial(counter);
            ++counter;
        }

        Console.WriteLine($"The e constant provided by Math.E is:   {Math.E}");
        Console.WriteLine($"The e constant provided by thie app is: {e}");
    }
示例#9
0
        static void Main(string[] args)
        {
            DisplayScreen pb23display = new DisplayScreen();

            pb23display.ProblemTitle  = "Problem 24";
            pb23display.ProblemHeader = "Lexicographic permutations";
            pb23display.Description   = "A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:\n012   021   102   120   201   210\nWhat is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 ? ";
            pb23display.DisplayHeader();

            //////////////////////////////////////////////////////////////////
            // More info on implemented algorithm on Wikipedia
            // https://en.wikipedia.org/wiki/Permutation
            //////////////////////////////////////////////////////////////////

            int[] items = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int   size  = items.Length;
            int   limit = 1000000;
            int   count = 1;
            long  possiblePermutations = Factorials.Factorial(size);

            Console.WriteLine("possible permutations :{0}\n", possiblePermutations);
            int k = 0;
            int l;

            while (count != limit)
            {
                //Implementing Generation in lexicographic order
                k = Permutations.FindK(items);
                l = Permutations.FindL(items, k);
                Permutations.SwapValues(k, l, items);
                Permutations.ReverseSeq(items, k);
                count++;
            }

            Console.Write("Permutation number {0}:   ", count);
            Permutations.DisplayArray(items);

            //////////////////////////////////////////////////////////////////

            pb23display.DisplayFooter();
            Console.ReadKey();
        }
示例#10
0
        public void Solution()
        {
            long number;  //Variable containing estimated required number

            minNumber = Factorials.GetFactorial(lastNumber);


            for (int i = lastNumber - 2; i > 1; i--)
            {
                number = minNumber % Factorials.GetFactorial(i) == 0 ? minNumber / Factorials.GetFactorial(i) : minNumber;
                for (int j = lastNumber; j >= 1; j--)
                {
                    if (number % j != 0)
                    {
                        break;
                    }
                    if (j == 1)
                    {
                        minNumber = number;
                        i++;
                    }
                }
            }
        }
示例#11
0
 private static async Task <int> IKnowWhoKnowsThis(int n) => await Factorials.FactorialDigitSum(n);