Пример #1
0
        static void Main(string[] args)
        {
            StringThing mainString = new StringThing();
            //building a string from 1-4 billion

            double size = 1000000;

            double[] powersOf3 = new double[13];
            for (int i = 0; i < powersOf3.Length; i++)
            {
                powersOf3[i] = Math.Pow(3, i + 1);
            }

            for (double i = 1; i < size; i++)
            {
                mainString.Append(i.ToString());
            }

            double Sum = 0;

            for (int i = 0; i < powersOf3.Length; i++)
            {
                double temp = Function(powersOf3[i], mainString, size);
                Sum += temp;
            }

            Console.WriteLine(Sum);
            Console.ReadKey();
        }
Пример #2
0
        static double Function(double number, StringThing S, double size)
        {
            double Count = 0;

            for (double i = 0; i < size; i++)
            {
                string temp = number.ToString();
                string gen  = S.Substring(i, temp.Length);
                if (gen == temp)
                {
                    Count++;
                }
                if (Count == number)
                {
                    return(i);
                }
            }
            throw new Exception("size not big enough");
        }