Guest User

Untitled

a guest
Apr 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. -module (histogram).
  2. -compile (export_all).
  3. -author ("Mr. M.S. Esquire Jonathan Raymond Hicks").
  4.  
  5. % Where is this damn file on a mac?
  6. % File = [ "a", "at", "red", "green", "dog"].
  7.  
  8. % This will need to come from the command line
  9. % Input = "reader".
  10.  
  11. % Break up the input into a histogram
  12. parse_input(Histo, [])->
  13. Histo;
  14.  
  15. parse_input(Histo, [H|T])->
  16. NewHisto = case lists:keyfind(H, 1, Histo) of
  17. false ->
  18. lists:keystore(H, 1, Histo, {H, 1});
  19. {H, N} ->
  20. lists:keyreplace(H, 1, Histo, {H, N+1})
  21. end,
  22. parse_input(NewHisto, T).
  23.  
  24. start_parse(Input)->
  25. parse_input([], Input).
  26.  
  27. % [{"a", 1}, {"d", 1}, {"e", 2}, {"r", 2}]
  28. % InputHisto = parse_input(Input).
  29.  
  30. match_letter([], Word)->
  31. {};
  32.  
  33. match_letter(Letter, Word)->
  34. match_letter(Letter, Word)
  35.  
  36. find_word(Word, [])->
  37. {true, Word};
  38.  
  39. find_word(Histo, [H,T])->
  40. NewHisto = case lists:filter(fun(E) -> [E] =:= match_letter(Histo, H) end, H) of
  41. false ->
  42. false;
  43. {H, N} ->
  44. lists:keyreplace(H, 1, Histo, {H, N-1})
  45. end,
  46. find_word(NewHisto, T).
  47.  
  48. start_find(InputHisto)->
  49. File = [ "a", "at", "red", "green", "dog"],
  50. case find_word(InputHisto, File) of
  51. {true, Word} ->
  52. io:format("~p", [Word]);
  53. _ ->
  54. end.
Add Comment
Please, Sign In to add comment