예제 #1
0
        private string GetAnswerForGivenStrings(string[] longNums)
        {
            List <StringNum> stringNums = longNums.Select(n => new StringNum(n)).ToList();

            StringNum result = stringNums.Aggregate((x, y) => StringNum.Add(x, y));

            return(result.ToString().Substring(0, 10));
        }
예제 #2
0
        public override string GetAnswer()
        {
            // yet another BigInteger=Cheating problem.
            // (then again, at this point, I'm reusing the same library I wrote
            // so I'm not sure there's even a point to it...)
            StringNum a      = new StringNum("1");
            StringNum b      = new StringNum("1");
            StringNum c      = new StringNum("2");
            int       cIndex = 3;

            while (c.ToString().Length < 1000)
            {
                a = b;
                b = c;
                c = StringNum.Add(a, b);
                cIndex++;
            }
            return(cIndex.ToString());
        }
예제 #3
0
        private long GetAnswerForSpecificPower(int powerOfTwo)
        {
            // I couldn't figure out any mathematical trick to derive this other than
            // simply multiplying out the number 2^1000 and then checking.
            // Also, once again, using BigInteger seemed way too much like cheating
            // (pretty sure these problems were written before the BigInteger library was available?)
            StringNum myVal = new StringNum("2");

            for (int i = 2; i <= powerOfTwo; i++)
            {
                myVal = StringNum.Add(myVal, myVal);
            }

            string result  = myVal.ToString();
            int    charSum = 0;

            foreach (char c in result)
            {
                charSum += (c - '0');
            }

            return(charSum);
        }
예제 #4
0
        public override string GetAnswer()
        {
            List <string> possibilities = new List <string>();

            Func <string, char, string> AppendNewChar = (s, c) => s + c;
            Func <string, char, string> PrefixNewChar = (s, c) => c + s;

            possibilities.Add("");

            possibilities = ApplyEachPossibleDigit(possibilities, AppendNewChar);
            possibilities = ApplyEachPossibleDigit(possibilities, AppendNewChar);
            possibilities = ApplyEachPossibleDigit(possibilities, AppendNewChar);
            possibilities = RemoveEntriesWhereLastThreeDontDivideBy(possibilities, 2);

            possibilities = ApplyEachPossibleDigit(possibilities, AppendNewChar);
            possibilities = RemoveEntriesWhereLastThreeDontDivideBy(possibilities, 3);

            possibilities = ApplyEachPossibleDigit(possibilities, AppendNewChar);
            possibilities = RemoveEntriesWhereLastThreeDontDivideBy(possibilities, 5);

            possibilities = ApplyEachPossibleDigit(possibilities, AppendNewChar);
            possibilities = RemoveEntriesWhereLastThreeDontDivideBy(possibilities, 7);

            possibilities = ApplyEachPossibleDigit(possibilities, AppendNewChar);
            possibilities = RemoveEntriesWhereLastThreeDontDivideBy(possibilities, 11);

            possibilities = ApplyEachPossibleDigit(possibilities, AppendNewChar);
            possibilities = RemoveEntriesWhereLastThreeDontDivideBy(possibilities, 13);

            possibilities = ApplyEachPossibleDigit(possibilities, AppendNewChar);
            possibilities = RemoveEntriesWhereLastThreeDontDivideBy(possibilities, 17);

            possibilities = ApplyEachPossibleDigit(possibilities, PrefixNewChar);

            StringNum answer = possibilities.Select(s => new StringNum(s)).Aggregate((x, y) => StringNum.Add(x, y));


            return(answer.ToString());
        }