Skip to content

Instantly share code, notes, and snippets.

@theburningmonk
Created September 7, 2011 14:30
Show Gist options
  • Save theburningmonk/1200719 to your computer and use it in GitHub Desktop.
Save theburningmonk/1200719 to your computer and use it in GitHub Desktop.
ProjectEuler - Problem 85 Solution
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