Example #1
0
        public string Run()
        {
            BigInteger max = 0;
            int maxIndex = 0;
            for (int i = 2; i <= 1000; i++)
            {
                if (Math.Sqrt(i) % 1 == 0)
                    continue;
                List<Tuple<BigInteger, BigInteger, BigInteger>> solutions = getPeriod(i);

                BigInteger tempMax = 0;
                if (solutions.Count % 2 == 0)
                {
                    tempMax = (BigInteger)(solutions.Last().Item1 * solutions.Last().Item3 + solutions.Last().Item2);
                }
                else
                {
                    solutions.Reverse();
                    Tuple<BigInteger, BigInteger, BigInteger>[] fractions = new Tuple<BigInteger, BigInteger, BigInteger>[solutions.Count];
                    fractions[0] = new Tuple<BigInteger, BigInteger, BigInteger>(1, solutions.ElementAt(0).Item3, 0);
                    for (int x = 1; x < fractions.Length; x++)
                    {
                        BigInteger numerator = (solutions.ElementAt(x).Item3 * fractions[x - 1].Item1) + (x > 1 ? fractions[x - 1].Item2 : 0);
                        fractions[x] = new Tuple<BigInteger, BigInteger, BigInteger>(numerator, fractions[x - 1].Item1, numerator + fractions[x - 1].Item1);
                    }
                    tempMax = (BigInteger)fractions.Last().Item3;
                }

                if (tempMax > max)
                {
                    maxIndex = i;
                    max = tempMax;
                }
            }

            return maxIndex.ToString();
        }
 public void LastTwoTuple()
 {
     const int expected = 42;
       var t = new Tuple<int, int>(1, 42);
       int actual = t.Last();
       Assert.AreEqual(expected, actual);
 }