Problem 1 From Project Euler
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.
——————————————————————————————————————————————————-
So after attempting the first puzzle, I realize I have a lot to learn. I need to brush up on my math…oh lord, I’m sure there is a cleaner way to do this then what I came up with. Ah lass, I guess brushing up on the math skills will have to be apart of this adventure.
using System;
namespace eulerProblem1
{
class Program
{
public static int getMultiples(int number)
{
int x = 1, multipleOfNumber = 0, sumOfNumber = 0, totalOfMultiple = 0;
while (number * x < 1000)
{
multipleOfNumber = x * number;
sumOfNumber = multipleOfNumber + totalOfMultiple;
totalOfMultiple = sumOfNumber;
x++;
}
return totalOfMultiple;
}
static void Main(string[] args)
{
int multiOfThree = 0;
int multiOfFive = 0;
int multiOfFifthteen = 0;
multiOfThree = getMultiples(3);
multiOfFive = getMultiples(5);
multiOfFifthteen = getMultiples(15);
int sumOfMultis = multiOfFive + multiOfThree - multiOfFifthteen;
Console.WriteLine("The sum of the totals of 3 under 1000, are: " + multiOfThree);
Console.WriteLine("The sum of the totals of 5 under 1000, are: " + multiOfFive);
Console.WriteLine("The sum of the totals of 15 under 1000, are: " + multiOfFifthteen);
Console.WriteLine("The sum of the totals under 1000, are: " + sumOfMultis);
Console.ReadLine();
}
}
}
One of the things I’m not happy with, is the main. It’s not a very good solution. While it works to show the output I wanted, it’s crude. Not very pragmatic of me I must say.