If you enjoy writing code and solving puzzles, you will love Project Euler. It is filled with mathematical puzzles which require you to write some code to get the answer. You could use the problems as a chance to write out the solution in a different programming language. 

To get you started I thought I would share the first problem with you. Please look away now if you don't want to see my solution.

It's not the best solution you will see for this question, but it works and can be used for other questions of this type without having to alter the inner code.

The problem:

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.

My solution:

public static void Main()
{

Console.WriteLine(GetSumOfMultiples(1, 10, new int[] { 3, 5 }));
//23

Console.WriteLine(GetSumOfMultiples(1, 1000, new int[] { 3, 5 }));
//233168
}


public static int GetSumOfMultiples(int startNumber, int endNumber, int[] multiples)
{
int sum = 0;
for (int x = startNumber; x < endNumber; x++)
{
foreach(int m in multiples)
{
if (IsMultiple(x, m))
{
sum += x;
break;
}
}
}
return sum;
}

public static bool IsMultiple(int x, int y)
{
return x % y == 0;
}

As you can see, I tested it out against their example and it works fine, then I ran it against the problem and it comes up with the correct answer.

LINQPad is ideal for this as it is so quick to get some code written and running without having to create a project in Visual Studio etc.

Anyway, have a go at the problems and let me know what you think. https://projecteuler.net/

Paul

Paul Seal

Umbraco MVP and .NET Web Developer from Derby (UK) who specialises in building Content Management System (CMS) websites using MVC with Umbraco as a framework. Paul is passionate about web development and programming as a whole. Apart from when he's with his wife and son, if he's not writing code, he's thinking about it or listening to a podcast about it.

Proudly sponsored by

Moriyama

  • Moriyama build, support and deploy Umbraco, Azure and ASP.NET websites and applications.
AppVeyor

  • CI/CD service for Windows, Linux and macOS
  • Build, test, deploy your apps faster, on any platform.
elmah.io

  • elmah.io is the easy error logging and uptime monitoring service for .NET.
  • Take back control of your errors with support for all .NET web and logging frameworks.
uSync Complete

  • uSync.Complete gives you all the uSync packages, allowing you to completely control how your Umbraco settings, content and media is stored, transferred and managed across all your Umbraco Installations.
uSkinned

  • More than a theme for Umbraco CMS, take full control of your content and design with a feature-rich, award-nominated & content editor focused website platform.
UmbHost

  • Affordable, Geo-Redundant, Umbraco hosting which gives back to the community by sponsoring an Umbraco Open Source Developer with each hosting package sold.