Created
May 18, 2020 18:06
-
-
Save pppillai/4c004672684216f50d91b96430622d3c to your computer and use it in GitHub Desktop.
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
-module(week227). | |
-compile([export_all]). | |
-include_lib("eunit/include/eunit.hrl"). | |
join(Xs, Ys) -> | |
accumulate(shunt(Xs, []), Ys). | |
shunt([], Ys) -> | |
Ys; | |
shunt([X|Xs], Ys) -> | |
shunt(Xs, [X|Ys]). | |
accumulate([] ,Result) -> | |
Result; | |
accumulate([X|Xs], Result) -> | |
accumulate(Xs, [X|Result]). | |
concat([]) -> | |
[]; | |
concat([X|Xs]) -> | |
join(X,concat(Xs)). | |
member(_N, []) -> | |
false; | |
member(N, [X|Xs]) -> | |
case X =:= N of | |
true -> | |
true; | |
false -> | |
member(N, Xs) | |
end. | |
perms([]) -> | |
[[]]; | |
perms(L) -> | |
[[X|Y] || X <- L, Y <- perms(L--[X])]. | |
tests() -> | |
?assertEqual(join([],[]),[]), | |
?assertEqual(join([1,2,3],[4,5,6]),[1,2,3,4,5,6]), | |
?assertEqual(concat(["hello", "world"]),"helloworld"), | |
% ?assertEqual(concat([]), []), | |
?assertEqual(perms([]), [[]]), | |
?assertEqual(perms([1,2,3]), [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks will go thorough