Browse Source

add solutions to problems #1 and #2

main
Colin McMillen 11 months ago
commit
e79afc4c7f
  1. 44
      Program.cs
  2. 0
      README.md
  3. 8
      euler.csproj

44
Program.cs

@ -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

8
euler.csproj

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