Name: Anonymous 2014-01-17 4:10
Sup /prog/, I need some algorithm help in F#. I'm fairly new to the language, and I'm working on a small dice library. My dice rolling code produces two values: an int seq of all the results of a set of dice (in the order that they were rolled), and a Map<int,int> of the results sorted as <faceRolled, quantityRolled>.
What's the quickest way to select the highest N and lowest (length-N) dice from either of the two collections? My current code is as follows:
What's the quickest way to select the highest N and lowest (length-N) dice from either of the two collections? My current code is as follows:
// The huge slowdown
let Omitted =
results // This is the int seq of unsorted results
|> Seq.sort
|> Seq.take (keepHighestCount - (Seq.length results))
|> Seq.countBy ( fun t -> t )
|> Map.ofSeq
// Extension function is a side effect free Map-Map
let Kept =
collapsedResults
|> MapExt.Remove Omitted