Created
September 7, 2011 14:30
-
-
Save theburningmonk/1200719 to your computer and use it in GitHub Desktop.
ProjectEuler - Problem 85 Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
let target = 2000000 | |
// function to work out the number of rects in a grid of x by y | |
let getRectCount x y = (x * x + x) * (y * y + y) / 4 | |
// try x and y dimensions up to 100 | |
let answer = | |
seq { | |
for x in 2..100 do | |
for y in 2..100 do | |
// get the grid area and the difference to the target count in a tuple | |
yield (x * y, Math.Abs(getRectCount x y - target)) | |
} | |
|> Seq.minBy (fun (area, diff) -> diff) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment