Created
April 13, 2019 12:10
-
-
Save msszczep/ec0661f247841e831661d121cbccc9ac to your computer and use it in GitHub Desktop.
Subanagram prototype in Erlang (dated May 3, 2008)
This file contains 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
#!/usr/bin/env escript | |
% This is an Erlang version of the subanagram generator. | |
% It works far faster and the code is far shorter. | |
% It takes a word at the command line as an argument. | |
% e.g.: `./subanagram_prototype.erl representative` | |
% Note: You need a file of words, one word per line, in the same directory as | |
% the script. | |
main([Original_word]) -> | |
List_of_words = file_parse("ospd3.txt"), | |
Subanagrams = sa_function(Original_word, List_of_words), | |
lists:map(fun(Word) -> io:fwrite("~s~n", [Word]) end, Subanagrams). | |
file_parse(File) -> | |
{ok, S} = file:open(File, [read,binary,raw]), | |
Size = filelib:file_size(File), | |
{ok, B1} = file:pread(S, 0, Size), | |
string:tokens(binary_to_list(B1), "\n"). | |
sa_function(Original, List_of_words) -> | |
lists:filter(fun(Subanagram) -> length(Subanagram -- Original) =:= 0 end, List_of_words). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment