Skip to content

Instantly share code, notes, and snippets.

@bradfordw
Forked from jonathan/histogram.erl
Created November 23, 2009 21:18
Show Gist options
  • Select an option

  • Save bradfordw/241387 to your computer and use it in GitHub Desktop.

Select an option

Save bradfordw/241387 to your computer and use it in GitHub Desktop.
-module(histo).
-compile(export_all).
-define(WORDS,[ "a", "at", "red", "green", "dog"]).
parse_input(Input) ->
lists:foldl(fun(Letter, D) -> dict:update(Letter, fun(N) -> N + 1 end, 1, D)
end, dict:new(),
[L || L <- Input]).
start_find(InputHisto) ->
Found = [ lists:filter(fun(E) -> lists:member(E, Word) end, dict:fetch_keys(InputHisto)) || Word <- ?WORDS],
[io:format("~p~n",[M]) || M <- lists:filter(fun(E) -> lists:member(E,Found) end, ?WORDS)].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment