Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. defmodule Frequent do
  2. def number( [num | tail] ) do
  3. number({num, 1}, tail, {num, 1})
  4. end
  5.  
  6. def number({num, count}, [ num | tail ], max) do
  7. number({num, count + 1}, tail, max)
  8. end
  9.  
  10. def number({_num, count} = current, [ diff | tail ], {_, max_count} = max) do
  11. if count > max_count do
  12. max = current
  13. end
  14. number({diff, 1}, tail, max)
  15. end
  16.  
  17. def number(_, [], max), do: max
  18. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement