Example #1
0
        public IActionResult Solve(EulerProblem problem)
        {
            var times = ProjectEulerAnswerGetter.Solve(problem.Id);

            if (times.Count == 0)
            {
                return(new BadRequestObjectResult($"The problem {problem.Id} is not solved yet."));
            }
            if (problem.IsSolved)
            {
                return(TrySaveChanges(times));
            }

            problem.Times = new long[4];
            if (!times.TryGetValue("C#", out problem.Times[0]))
            {
                problem.Times[0] = -1;
            }
            if (!times.TryGetValue("Java", out problem.Times[1]))
            {
                problem.Times[1] = -1;
            }
            if (!times.TryGetValue("C++", out problem.Times[2]))
            {
                problem.Times[2] = -1;
            }
            if (!times.TryGetValue("Python", out problem.Times[3]))
            {
                problem.Times[3] = -1;
            }

            problem.IsSolved  = true;
            problem.SolveDate = new DateTime();
            return(TrySaveChanges(times));
        }
Example #2
0
        public IActionResult RefreshAll(bool shouldOverride)
        {
            var ping = new Ping();

            if (!ProjectEulerScraper.IsAvailable("https://projecteuler.net/").Result)
            {
                return(new NotFoundObjectResult("projecteuler.net is not reachable."));
            }
            Warn("Refreshing all problems...");
            for (var i = 1;; i++)
            {
                if (!ProjectEulerScraper.ProblemExists("https://projecteuler.net/problem=" + i))
                {
                    break;
                }

                var data = ProjectEulerScraper.GetAll(i);

                var problem = Context.EulerProblems.Find(i);
                if (problem == null)
                {
                    Context.Add(problem = new EulerProblem(i, null, null));
                }

                problem.Title       = data[EulerProblemPart.Title];
                problem.Description = data[EulerProblemPart.Description];
                problem.PublishDate = DateParser.ParseEulerDate(data[EulerProblemPart.PublishDate]);
                problem.Difficulty  = data[EulerProblemPart.Difficulty] == null
                                         ? null
                                         : (int?)int.Parse(
                    Regex.Replace(data[EulerProblemPart.Difficulty], @"[^\d]", ""));
                Info($"Problem {i} created: " + problem);
            }

            Info("Finished refreshing all problems.");
            return(TrySaveChanges(Context.EulerProblems));
        }
Example #3
0
 public IActionResult CreateProblem(EulerProblem problem)
 {
     Context.Add(problem);
     Info("Created Problem: " + problem);
     return(TrySaveChanges(problem));
 }
 public IActionResult Solve(EulerProblem problem)
 {
     return(_service.Solve(problem));
 }
 public IActionResult Post(EulerProblem problem)
 {
     return(_service.CreateProblem(problem));
 }