Skip to content

Instantly share code, notes, and snippets.

@adilakhter
Created November 26, 2012 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adilakhter/4151076 to your computer and use it in GitHub Desktop.
Save adilakhter/4151076 to your computer and use it in GitHub Desktop.
count elements that are greater than avg of list elements
let countElements list =
let rec countElementsAux sum length l=
match l with
| [] -> (sum/length, 0) // computing average from sum and length accumulator
| x :: xs ->
let (avg,count) = countElementsAux (x+ sum) (length+1) xs
if x < avg then (avg,count) else (avg,count+1)
let (avg, count) = countElementsAux 0 0 list
count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment