Example #1
0
        public string GetAnswer()
        {
            int[]      fn_2 = new int[] { 1 };
            int[]      fn_1 = new int[] { 1 };
            BigInteger f1   = 1;
            BigInteger f2   = 1;
            int        i    = 3;

            while (true)
            {
                BigInteger fnBig = f1 + f2;
                int[]      fn    = Add(fn_1, fn_2);
                if (IsPandigitalFibonacci(fn))
                {
                    int digits          = (int)Math.Floor(BigInteger.Log10(fnBig) + 1);
                    var dividend        = BigInteger.Pow(10, digits - 9);
                    var firstNineDigits = fnBig / dividend;
                    if (Utils.IsPandigital(firstNineDigits.ToString(), false))
                    {
                        return(i.ToString());
                    }
                }

                fn_2 = fn_1;
                fn_1 = fn;
                f2   = f1;
                f1   = fnBig;
                i++;
            }
        }
Example #2
0
 public static int IntLength(BigInteger i)
 {
     if (i < 0)
     {
         throw new ArgumentOutOfRangeException();
     }
     if (i == 0)
     {
         return(1);
     }
     {
         return((int)Math.Floor(BigInteger.Log10(i)) + 1);
     }
 }
Example #3
0
        public static int Problem104Old()
        {
            var        i    = 1;
            BigInteger prev = 0;
            BigInteger cur  = 1;

            while (cur.ToString().Length < 18)
            {
                var temp = cur;
                cur  = cur + prev;
                prev = temp;
                i++;
            }


            while (true)
            {
                var tail = (long)(cur % 1000000000);
                if (tail.IsPandigital())
                {
                    var l    = (int)(BigInteger.Log10(cur) + 1);
                    var head = (long)(cur / BigInteger.Pow(10, l - 9));

                    if (head.IsPandigital())
                    {
                        return(i);
                    }
                }


                var temp = cur;
                cur  = cur + prev;
                prev = temp;
                i++;
            }
        }