Permalink
Browse files

Solution for problem 31

  • Loading branch information...
1 parent 4847155 commit b2284d1d36de695ca1e1d96d516c80b11bf5ceac @sfoutrier committed Apr 4, 2012
Showing with 88 additions and 0 deletions.
  1. +6 −0 Euler.sln
  2. +56 −0 Euler31/Euler31.fsproj
  3. +26 −0 Euler31/Program.fs
View
@@ -63,6 +63,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Euler29", "Euler29\Euler29.
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Euler30", "Euler30\Euler30.fsproj", "{5582402A-E7E2-4358-AB6D-7790720A9951}"
EndProject
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Euler31", "Euler31\Euler31.fsproj", "{FCB50022-9026-4580-BAF1-2DCA82E12750}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
@@ -193,6 +195,10 @@ Global
{5582402A-E7E2-4358-AB6D-7790720A9951}.Debug|x86.Build.0 = Debug|x86
{5582402A-E7E2-4358-AB6D-7790720A9951}.Release|x86.ActiveCfg = Release|x86
{5582402A-E7E2-4358-AB6D-7790720A9951}.Release|x86.Build.0 = Release|x86
+ {FCB50022-9026-4580-BAF1-2DCA82E12750}.Debug|x86.ActiveCfg = Debug|x86
+ {FCB50022-9026-4580-BAF1-2DCA82E12750}.Debug|x86.Build.0 = Debug|x86
+ {FCB50022-9026-4580-BAF1-2DCA82E12750}.Release|x86.ActiveCfg = Release|x86
+ {FCB50022-9026-4580-BAF1-2DCA82E12750}.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>{fcb50022-9026-4580-baf1-2dca82e12750}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>Euler31</RootNamespace>
+ <AssemblyName>Euler31</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <Name>Euler31</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\Euler31.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\Euler31.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,26 @@
+// http://projecteuler.net/problem=31
+
+// the basic bruteforce algo ...
+[<EntryPoint>]
+let main args =
+
+ let moneys = [| 1; 2; 5; 10; 20; 50; 100; 200 |]
+
+ let moneysFrom n = seq {for i in moneys do if i >= n then yield i}
+
+ let rec seqOfMoney moneyList curSum =
+ seq {
+ let firstOrDefault = match moneyList with [] -> Array.min moneys | x::_ -> x
+ for i in (moneysFrom firstOrDefault) do
+ match i + curSum with
+ | 200 -> yield (i :: moneyList)
+ | x when x < 200 -> yield! (seqOfMoney (i :: moneyList) x)
+ | _ -> ()
+ }
+
+ let allSeqOfMoney = seqOfMoney [] 0
+
+ printfn "%d" (Seq.length allSeqOfMoney)
+
+ let _ = System.Console.ReadKey true
+ 0

0 comments on commit b2284d1

Please sign in to comment.