Commits

Craig Phillips  committed 8f5f781

Added Problem 9 and realted tests.

  • Participants
  • Parent commits 8bf9cd9

Comments (0)

Files changed (4)

File ProjectEuler.Tests/Problem9Tests.cs

+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace ProjectEuler.Tests
+{
+	[TestClass]
+	public class Problem9Tests
+	{
+		[TestMethod]
+		public void Problem9Test()
+		{
+			var problem9 = new Problem9();
+			var result = problem9.ProductOfSpecialPythagoreanTriplet();
+			Assert.AreEqual(31875000, result);
+		}
+	}
+}

File ProjectEuler.Tests/ProjectEuler.Tests.csproj

     <Compile Include="Problem6Tests.cs" />
     <Compile Include="Problem7Tests.cs" />
     <Compile Include="Problem8Tests.cs" />
+    <Compile Include="Problem9Tests.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Problem1Tests.cs" />
   </ItemGroup>

File ProjectEuler/Problem9.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectEuler
+{
+	public class Problem9
+	{
+		public int ProductOfSpecialPythagoreanTriplet()
+		{
+			var a = 0;
+			var b = 0;
+			var c = 0;
+			var s = 1000;
+			var found = false;
+			for (a = 1; a < s / 3; a++)
+			{
+				for (b = a; b < s / 2; b++)
+				{
+					c = s - a - b;
+
+					if (a * a + b * b == c * c)
+					{
+						found = true;
+						break;
+					}
+				}
+
+				if (found)
+				{
+					break;
+				}
+			}
+			return a*b*c;
+		}
+	}
+}

File ProjectEuler/ProjectEuler.csproj

     <Compile Include="Problem6.cs" />
     <Compile Include="Problem7.cs" />
     <Compile Include="Problem8.cs" />
+    <Compile Include="Problem9.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>