Permalink
Browse files

Solution for problem 15

  • Loading branch information...
1 parent eaeae7c commit 5dad021c509c97e205c0935e5ee1523fd81e71d1 @sfoutrier committed Apr 2, 2012
Showing with 79 additions and 0 deletions.
  1. +6 −0 Euler.sln
  2. +56 −0 Euler15/Euler15.fsproj
  3. +17 −0 Euler15/Program.fs
View
@@ -51,6 +51,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Euler24", "Euler24\Euler24.
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Euler25", "Euler25\Euler25.fsproj", "{58B283F6-14DE-48D3-9E30-474DC2429E70}"
EndProject
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Euler15", "Euler15\Euler15.fsproj", "{7B199AF6-DBD2-435D-A150-4421B789FF12}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
@@ -157,6 +159,10 @@ Global
{58B283F6-14DE-48D3-9E30-474DC2429E70}.Debug|x86.Build.0 = Debug|x86
{58B283F6-14DE-48D3-9E30-474DC2429E70}.Release|x86.ActiveCfg = Release|x86
{58B283F6-14DE-48D3-9E30-474DC2429E70}.Release|x86.Build.0 = Release|x86
+ {7B199AF6-DBD2-435D-A150-4421B789FF12}.Debug|x86.ActiveCfg = Debug|x86
+ {7B199AF6-DBD2-435D-A150-4421B789FF12}.Debug|x86.Build.0 = Debug|x86
+ {7B199AF6-DBD2-435D-A150-4421B789FF12}.Release|x86.ActiveCfg = Release|x86
+ {7B199AF6-DBD2-435D-A150-4421B789FF12}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{7b199af6-dbd2-435d-a150-4421b789ff12}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>Euler15</RootNamespace>
+ <AssemblyName>Euler15</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <Name>Euler15</Name>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <Tailcalls>false</Tailcalls>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <WarningLevel>3</WarningLevel>
+ <PlatformTarget>x86</PlatformTarget>
+ <DocumentationFile>bin\Debug\Euler15.XML</DocumentationFile>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <Tailcalls>true</Tailcalls>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <WarningLevel>3</WarningLevel>
+ <PlatformTarget>x86</PlatformTarget>
+ <DocumentationFile>bin\Release\Euler15.XML</DocumentationFile>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="FSharp.Core" />
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Numerics" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.fs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets" Condition="!Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
+ <Import Project="$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
@@ -0,0 +1,17 @@
+// http://projecteuler.net/problem=15
+
+[<EntryPoint>]
+let main args =
+ // the result is the number of permutations of 2n elements with twice n repetitions (go right and go down)
+ // the formula is C(2n)(n,n) = (2n)!/(n!*n!)
+
+ let rec fact = function
+ | n when n = bigint.One -> bigint.One
+ | n -> n * fact (n - bigint.One)
+
+ let permutations n = fact ((bigint 2) * n) /(( fact n ) * ( fact n ))
+
+ printfn "%O" (permutations (bigint 20))
+
+ let _ = System.Console.ReadKey true
+ 0

0 comments on commit 5dad021

Please sign in to comment.