Skip to content

Instantly share code, notes, and snippets.

@daniel-chambers
Forked from johnazariah/mine.fs
Created July 31, 2014 01:32
Show Gist options
  • Save daniel-chambers/ff9ce5991e589d7840ce to your computer and use it in GitHub Desktop.
Save daniel-chambers/ff9ce5991e589d7840ce to your computer and use it in GitHub Desktop.
type Building = {
left : int
right : int
height : int
}
let buildings : Building[] = [| (* ... *) |]
let getHeight building = building.height
let getWidth building = building.right - building.left
let getArea building = getHeight building * getWidth building
type Op = {
map : Building -> int
reduce : int -> int -> int
zero : int
}
let maxHeight = {
map = getHeight
reduce = (fun l r -> if l < r then l else r)
zero = System.Int32.MinValue
}
let minWidth = {
map = getWidth
reduce = (fun l r -> if l > r then l else r)
zero = System.Int32.MaxValue
}
let totalArea = {
map = getArea
reduce = (+)
zero = 0
}
let fs = [| maxHeight; minWidth; totalArea |]
let limits =
fs
|> Seq.map (fun f ->
buildings
|> Seq.map f.map
|> Seq.fold f.reduce f.zero)
|> Seq.toArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment