36 lines
1.3 KiB
Erlang
36 lines
1.3 KiB
Erlang
-module(cw).
|
|
-import(string,[len/1, substr/3]).
|
|
-import(maps,[foreach/2]).
|
|
-export([start/0, test_find/2, ttt/5, checkMatch/3, find_patterns/2]).
|
|
|
|
checkMatch(Test, Wanted, CheckPos) when Test == Wanted ->
|
|
CheckPos -1;
|
|
checkMatch(Test, Wanted, CheckPos) when Test /= Wanted ->
|
|
"".
|
|
|
|
ttt(Data, Pattern, DataLength, PatternLength, StartPos) when StartPos >= (DataLength - (PatternLength -1)) ->
|
|
checkMatch(substr(Data,StartPos,PatternLength), Pattern, StartPos);
|
|
ttt(Data, Pattern, DataLength, PatternLength, StartPos) when StartPos < (DataLength - (PatternLength -1)) ->
|
|
[checkMatch(substr(Data,StartPos,PatternLength), Pattern, StartPos)| ttt(Data, Pattern, DataLength, PatternLength, StartPos+1)].
|
|
|
|
test_find(Data, Pattern) ->
|
|
DataLength = len(Data),
|
|
PatternLength = len(Pattern),
|
|
ttt(Data,Pattern, DataLength, PatternLength, 1).
|
|
|
|
|
|
test_helloworld(Data, []) ->
|
|
"";
|
|
test_helloworld(Data, [H|T]) ->
|
|
[test_find(Data, H) | test_helloworld(Data, T)].
|
|
|
|
find_patterns(Data, Pattern) ->
|
|
io:format(Pattern).
|
|
|
|
start() ->
|
|
io:format("~p~n",[test_helloworld("AAA",["AA"])]),
|
|
io:format("~p~n",[test_helloworld("AAA",["AA", "AC"])]),
|
|
io:format("~p~n",[test_helloworld("AAC",["AA", "AC"])]),
|
|
io:format("~p~n~n",[test_helloworld("AAAAAAAAAAAAAAACCCAAAAAAAAAAAAACCCA",["CC", "CCC"])]),
|
|
io:format("done~n").
|