Created
November 26, 2012 22:27
-
-
Save adilakhter/4151076 to your computer and use it in GitHub Desktop.
count elements that are greater than avg of list elements
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
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