Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. -module (numcount).
  2. -export ([load/1,count/3,compare/1]).
  3. %modification of charcount example
  4. load(F)->
  5. {ok, List} = file:read_file(F),
  6. L=binary_to_list(List),
  7. io:fwrite("Result\n"),
  8. Result=compare(L),
  9. Result.
  10.  
  11.  
  12. count(Ch, [],N)->N;
  13. count(Ch, [H|T],N) ->
  14. case Ch==H of
  15. true-> count(Ch,T,N+1);
  16. false -> count(Ch,T,N)
  17. end.
  18.  
  19. compare(L)->
  20. Alph=[$0,$1,$2,$3,$4,$5,$6,$7,$8,$9],
  21. rgo(Alph,L,[]).
  22.  
  23. rgo([H|T],L,Result)->
  24. N=count(H,L,0),
  25. Result2=Result++[{[H],N}],
  26. rgo(T,L,Result2);
  27. rgo([],L,Result)->Result.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement