Created
November 23, 2009 21:17
-
-
Save jonathan/241384 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment