Ejemplo n.º 1
0
        public override object Run(RunModes runMode, object input, bool Logging)
        {
            for (int i = 10; i < 100; i++)
            {
                for (int j = i + 1; j < 100; j++)
                {
                    var numDigit1   = i / 10;
                    var numDigit2   = i % 10;
                    var denomDigit1 = j / 10;
                    var denomDigit2 = j % 10;

                    if ((numDigit1 == denomDigit2 && denomDigit1 != 0 && (double)numDigit2 / (double)denomDigit1 == (double)i / (double)j) ||
                        (numDigit2 == denomDigit1 && denomDigit2 != 0 && (double)numDigit1 / (double)denomDigit2 == (double)i / (double)j) ||
                        (numDigit2 == denomDigit2 && denomDigit1 != 0 && (double)numDigit1 / (double)denomDigit1 == (double)i / (double)j && numDigit2 != 0))
                    {
                        WeirdFractions.Add(new Fraction(i, j));
                    }
                }
            }
            var numerator   = WeirdFractions.Aggregate((BigInteger)1, (product, item) => product * item.Numerator);
            var denominator = WeirdFractions.Aggregate((BigInteger)1, (product, item) => product * item.Denominator);
            var gcd         = GreatestCommonDenominator.Get(new List <BigInteger> {
                numerator, denominator
            });

            return(denominator / gcd);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //Quick-find
            QuickFindUF grid = new QuickFindUF(10);

            grid.Union(2, 3);
            grid.Union(3, 6);
            grid.Union(6, 5);
            Console.WriteLine($"Does 2 and 5 connect? {grid.Connected(2, 5)}");
            Console.WriteLine($"Does 6 and 1 connect? {grid.Connected(1, 6)}");

            //Quick-union
            QuickUnionUF quuf = new QuickUnionUF(10);

            quuf.Union(2, 3);
            quuf.Union(3, 6);
            quuf.Union(6, 5);
            Console.WriteLine($"Does 2 and 5 connect? {quuf.Connected(2, 5)}");
            Console.WriteLine($"Does 6 and 1 connect? {quuf.Connected(1, 6)}");

            Console.WriteLine(GreatestCommonDenominator.GetGCD(9, 0));
        }