add solutions to problems #1 and #2

This commit is contained in:
Colin McMillen 2020-11-17 13:46:20 -05:00
commit e79afc4c7f
3 changed files with 52 additions and 0 deletions

44
Program.cs Normal file
View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
namespace Euler {
class Program {
static int Problem1() {
int sum = 0;
for (int i = 1; i < 1000; i++) {
if (i % 3 == 0 || i % 5 == 0) {
sum += i;
}
}
return sum;
}
static long Problem2() {
int max = 4_000_000;
var fibs = new List<int>();
fibs.Add(1);
fibs.Add(2);
while (fibs[fibs.Count - 1] < max) {
int num = fibs[fibs.Count - 1] + fibs[fibs.Count - 2];
fibs.Add(num);
}
int sum = 0;
foreach (int i in fibs) {
if (i % 2 == 0 && i <= max) {
sum += i;
}
}
return sum;
}
static void Main(string[] args) {
Console.WriteLine(Problem2());
}
}
}

0
README.md Normal file
View File

8
euler.csproj Normal file
View File

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>