Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
10
Task/Averages-Mode/F-Sharp/averages-mode-1.fs
Normal file
10
Task/Averages-Mode/F-Sharp/averages-mode-1.fs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
let mode (l:'a seq) =
|
||||
l
|
||||
|> Seq.countBy (fun item -> item) // Count individual items
|
||||
|> Seq.fold // Find max counts
|
||||
(fun (cp, lst) (item, c) -> // State is (count, list of items with that count)
|
||||
if c > cp then (c, [item]) // New max - keep count and a list of the single item
|
||||
elif c = cp then (c, item :: lst) // New element with max count - prepend it to the list
|
||||
else (cp,lst)) // else just keep old count/list
|
||||
(0, [Unchecked.defaultof<'a>]) // Start with a count of 0 and a dummy item
|
||||
|> snd // From (count, list) we just want the second item (the list)
|
||||
6
Task/Averages-Mode/F-Sharp/averages-mode-2.fs
Normal file
6
Task/Averages-Mode/F-Sharp/averages-mode-2.fs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
> mode ["a"; "b"; "c"; "c"];;
|
||||
val it : string list = ["c"]
|
||||
> mode ["a"; "b"; "c"; "c";"a"];;
|
||||
val it : string list = ["c"; "a"]
|
||||
> mode [1;2;1;3;2;0;0];;
|
||||
val it : int list = [0; 2; 1]
|
||||
Loading…
Add table
Add a link
Reference in a new issue