Tool – ProjectEuler Solution

After reading some reviews of interviews at Microsoft and Google, I am inspired to train myself for solving mathematical problems and writing algorithms. http://projecteuler.net/ is my first “mountain peak” to conquer. This website has until now more than 350 problems of many fields in mathematics. It’s suitable for training to write efficient algorithms to solve complicated computing tasks. I’m just at starter level and don’t have much time for it but when I have free time I’ll solve some of them. To manage all solved problems, I have written a GUI Tool which loads all problems as plugins, allow me to enter argument with its value and invoke the calculate method to get result back.
The tool will scan folder “Extensions” at its startup directory and load all plugins written for him. Therefore you can write your own plugin, copy to “Extensions” folder and use the tool as GUI to run your solution.
I also created a Web-version of this tool but the website version is very limited. It doesn’t permit to upload your solutions (I know you’re good hackers) and customize value of argument (I’ll improve the website version in next version so that you can customize the input).

  • Version: 1.0.0.0
  • Supported OS: All Windows

NOTE: If this tool doesn’t work with your system, post here your errors.

LINK DOWN: http://hintdesk.com/Web/Tool/ProjectEulerSolution.zip

WEBSITE: http://projecteulersolutionweb.apphb.com/ (the website is pretty slow at first load. Sorry for that, I don’t have any Windows host to host my application)

HISTORY:

  • [1.0.0.0] : Beta Version

SCREENSHOT

ProjectEuler Solution

PLUGIN INSTRUCTION
– To write your own plugin which works with this GUI tool, you should create a library and add reference to libraries

  • RPESPlugIn.dll (which can be found in “Extensions” folder)
  • System.ComponentModel.Composition.dll
  • – Your solution class must implement the IProblemSolution interface and define some attributes as example below

    [ProblemSolutionAttribute("Problem 1", @"If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
    
    Find the sum of all the multiples of 3 or 5 below 1000.
    ")]
    public class Problem1Solution : IProblemSolution
    {
    	public string GetResult(List<ProblemArg> probArgs)
    	{
    		Stopwatch stopWatch = new Stopwatch();
    		stopWatch.Start();
    
    		double result = Calculate(probArgs);
    
    		stopWatch.Stop();
    		return string.Format("Result: {0}\nTime elapsed: {1} ms", result, stopWatch.ElapsedMilliseconds);
    	}
    
    	public double Calculate(List<ProblemArg> probArgs)
    	{
    		int n = Convert.ToInt32(probArgs.First().Value) - 1;
    		return SumDivisibleBy(n, 3) + SumDivisibleBy(n, 5) - SumDivisibleBy(n, 15);
    	}
    
    	public double ProjectEulerCalculate(List<ProblemArg> probArgs)
    	{
    		throw new NotImplementedException();
    	}
    
    	private int SumDivisibleBy(int n, int factor)
    	{
    		int i = (n / factor);
    		return factor * i * (i + 1) / 2;
    	}
    
    	public List<ProblemArg> RequiredInputArgs
    	{
    		get
    		{
    			return new List<ProblemArg>() { new ProblemArg { DefaultValue = "1000", Name = "Integer n", RegularExpression = "^[0-9.]+$", MaxLength = Int32.MaxValue.ToString().Length } };
    		}
    	}
    }
    

    – There are 2 required attributes for your class solution. One is the name of problem which should be shown in combo box and the other is the description of problem which should be displayed in text box.

    – If you want to allow user enter value of argument, you should define the RequiredInputArgs property to give a list of argument back. The list can contain more arguments which will be show in list box under problem description.

    – The GetResult(List probArgs) gives you a signal that the user want to invoke your solution with his defined value (if any). In this function you can make your calculation (which can be in Calculate(List probArgs) function but it must not) and give the result back with type of string.

    So it’s pretty easy to write extension for this GUI tool. Try yourself to write your own solution and let this tool manages all solution for you.