Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(gowno).
- -author("marcin").
- -compile([export_all]).
- getGowno([]) -> [];
- getGowno([X]) -> [X];
- getGowno([H|Chuj]) -> lists:map( fun(X) -> deepMerge(H, getGowno(X)) end, Chuj).
- deepMerge(_, []) -> [];
- deepMerge(X, [[H|T]|C]) -> [deepMerge(X,[H|T])] ++ deepMerge(X, C);
- deepMerge(X, [H|T]) -> [X,H] ++ T.
- reduceBrackets([[H|T]]) -> reduceBrackets([H|T]);
- reduceBrackets([H|T]) -> [H|T];
- reduceBrackets([]) -> [];
- reduceBrackets(X) -> X.
- deepLength([]) -> 0;
- deepLength([_]) -> 1;
- deepLength([H|T]) -> lists:max(lists:map(fun(X) -> 1 + deepLength(X) end, [H|T]));
- deepLength(_) -> 0.
- alignLists([]) -> [];
- alignLists([H|C]) ->
- ReducedA = reduceBrackets([H|C]),
- LengthA = deepLength(ReducedA),
- LengthH = deepLength(H),
- LengthC = deepLength(C),
- if (LengthA == 1) -> ReducedA;
- (LengthH > LengthC) -> alignLists(H) ++ [alignLists(C)];
- (LengthH < LengthC) -> [alignLists(H)] ++ alignLists(C);
- true ->
- if ((LengthH == 1) or (LengthH == 0)) ->
- [H] ++ C;
- true ->
- lists:merge(H,C)
- end
- end;
- alignLists(X) -> X.
- alignBeats([]) -> [];
- alignBeats([H|T]) -> lists:map(fun(X) -> reduceBrackets(X) end, [H|T]).
- findPaths([H|T]) -> alignBeats(alignLists(getGowno([H|T]))).
- main() -> io:write(findPaths([1,[2,[3],[4]],[5]])).%io:write(alignBeats(alignLists([[[[1,2,3,6]],[1,2,4]],[1,5]]))).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement