Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding solution for problem 33

  • Loading branch information...
commit 932b8f0c6b5fb40104bd75c3432b30ab6f407dce 1 parent 95ed907
@sfoutrier authored
Showing with 121 additions and 0 deletions.
  1. +6 −0 Euler.sln
  2. +56 −0 Euler33/Euler33.fsproj
  3. +59 −0 Euler33/Program.fs
View
6 Euler.sln
@@ -67,6 +67,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Euler32", "Euler32\Euler32.
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Euler16", "Euler16\Euler16.fsproj", "{A4A33341-3956-4C5C-BABF-35FB5D8F9220}"
EndProject
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Euler33", "Euler33\Euler33.fsproj", "{E4C5B21D-84F0-4E1A-975A-7D24A75C55BA}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
@@ -205,6 +207,10 @@ Global
{A4A33341-3956-4C5C-BABF-35FB5D8F9220}.Debug|x86.Build.0 = Debug|x86
{A4A33341-3956-4C5C-BABF-35FB5D8F9220}.Release|x86.ActiveCfg = Release|x86
{A4A33341-3956-4C5C-BABF-35FB5D8F9220}.Release|x86.Build.0 = Release|x86
+ {E4C5B21D-84F0-4E1A-975A-7D24A75C55BA}.Debug|x86.ActiveCfg = Debug|x86
+ {E4C5B21D-84F0-4E1A-975A-7D24A75C55BA}.Debug|x86.Build.0 = Debug|x86
+ {E4C5B21D-84F0-4E1A-975A-7D24A75C55BA}.Release|x86.ActiveCfg = Release|x86
+ {E4C5B21D-84F0-4E1A-975A-7D24A75C55BA}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
56 Euler33/Euler33.fsproj
@@ -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>{e4c5b21d-84f0-4e1a-975a-7d24a75c55ba}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>Euler33</RootNamespace>
+ <AssemblyName>Euler33</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <Name>Euler33</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\Euler33.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\Euler33.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
59 Euler33/Program.fs
@@ -0,0 +1,59 @@
+// http://projecteuler.net/problem=32
+
+[<EntryPoint>]
+let main args =
+
+ let allFractions =
+ seq { for a in {10..99} do
+ for b in {a..99} -> a, b }
+
+ let rec pgcd a b =
+ if a < b then
+ pgcd b a
+ else
+ match a % b with
+ | 0 -> b
+ | c -> pgcd b c
+
+ let simplifyedFraction (a, b) =
+ let c = pgcd a b
+ a / c, b / c
+
+ let removeIdentical (a, b) =
+ if a / 10 = b / 10 then
+ Some (a % 10, b % 10)
+ else if a / 10 = b % 10 then
+ Some (a % 10, b / 10)
+ else if a % 10 = b / 10 then
+ Some (a / 10, b % 10)
+ else if a % 10 = b % 10 then
+ Some (a / 10, b / 10)
+ else
+ None
+
+ let isCuriousFraction (a, b) =
+ if a >= b || (a % 10 = 0 && b % 10 = 0) then
+ false
+ else
+ match removeIdentical (a, b) with
+ | None -> false
+ | Some (i, j) ->
+ let k, l = simplifyedFraction (a, b)
+ Seq.exists (fun x -> i = k * x && j = l * x) {1..9}
+
+ (*Seq.iter (fun (a, b) ->
+ match removeIdentical (a, b) with
+ | Some (c, d) -> printfn "%d / %d = %d / %d" a b c d
+ | None -> () )
+ (Seq.filter isCuriousFraction allFractions)*)
+
+ let resN, resD =
+ Seq.reduce
+ (fun (x, y) (z, t) -> x * z, y * t)
+ (Seq.filter isCuriousFraction allFractions)
+ |> simplifyedFraction
+
+ printfn "%d / %d " resN resD
+
+ let _ = System.Console.ReadKey true
+ 0
Please sign in to comment.
Something went wrong with that request. Please try again.