コード例 #1
0
        /// <summary>
        /// https://projecteuler.net/problem=73
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        public static Result CountingFractionsInRange(Problem arguments)
        {
            var d      = arguments.IntNumber;
            var bounds = arguments.ListOfNumbers;
            var begin  = new UtilityMath.Fraction(bounds[0], bounds[1]);
            var end    = new UtilityMath.Fraction(bounds[2], bounds[3]);

            var list   = UtilityMath.GenerateFareySequence(d);
            var count  = list.Count(fraction => fraction > begin && fraction < end);
            var answer = count.ToString();

            var message = string.Format("The number of fractions lie between {0} and {1} in the sorted set of reduced proper fractions for d ≤ {2} is {3}.", begin.ToString(), end.ToString(), d, answer);

            if (Answers[arguments.Id] != answer)
            {
                message += string.Format(" => INCORRECT ({0})", Answers[arguments.Id]);
            }
            var r = new Result(arguments.Id, message)
            {
                Answer = answer
            };

            return(r);
        }
コード例 #2
0
        /// <summary>
        /// https://projecteuler.net/problem=71
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        public static Result OrderedFractions(Problem arguments)
        {
            var integers = arguments.ListOfNumbers;
            var key      = new UtilityMath.Fraction(integers[0], integers[1]);
            var d        = arguments.IntNumber;

            var    sort_list = UtilityMath.GetReducedProperFractions(d, key, true).ToList();
            string answer    = sort_list[0].Numerator.ToString();

            var message = string.Format("The numerator of the fraction immediately to the left of {0} is {1}.", key.ToString(), answer);

            if (Answers[arguments.Id] != answer)
            {
                message += string.Format(" => INCORRECT ({0})", Answers[arguments.Id]);
            }
            var r = new Result(arguments.Id, message)
            {
                Answer = answer
            };

            return(r);
        }