Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module (histogram).
- -compile (export_all).
- -author ("Mr. M.S. Esquire Jonathan Raymond Hicks").
- % Where is this damn file on a mac?
- % File = [ "a", "at", "red", "green", "dog"].
- % This will need to come from the command line
- % Input = "reader".
- % Break up the input into a histogram
- parse_input(Histo, [])->
- Histo;
- parse_input(Histo, [H|T])->
- NewHisto = case lists:keyfind(H, 1, Histo) of
- false ->
- lists:keystore(H, 1, Histo, {H, 1});
- {H, N} ->
- lists:keyreplace(H, 1, Histo, {H, N+1})
- end,
- parse_input(NewHisto, T).
- start_parse(Input)->
- parse_input([], Input).
- % [{"a", 1}, {"d", 1}, {"e", 2}, {"r", 2}]
- % InputHisto = parse_input(Input).
- match_letter([], Word)->
- {};
- match_letter(Letter, Word)->
- match_letter(Letter, Word)
- find_word(Word, [])->
- {true, Word};
- find_word(Histo, [H,T])->
- NewHisto = case lists:filter(fun(E) -> [E] =:= match_letter(Histo, H) end, H) of
- false ->
- false;
- {H, N} ->
- lists:keyreplace(H, 1, Histo, {H, N-1})
- end,
- find_word(NewHisto, T).
- start_find(InputHisto)->
- File = [ "a", "at", "red", "green", "dog"],
- case find_word(InputHisto, File) of
- {true, Word} ->
- io:format("~p", [Word]);
- _ ->
- end.
Add Comment
Please, Sign In to add comment