Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(solution).
- -export([main/0]).
- rotate({A0,A1},{B0,B1},{C0,C1}) ->
- (B0-A0)*(C1-B1)-(B1-A1)*(C0-B0).
- sort_list(StartPoint,All) ->
- lists:sort(fun(X,Y)-> Rot=rotate(StartPoint,X,Y), if Rot=<0 -> true; Rot>0 -> false end end,All).
- find_start_point([{A,B}|[]]) -> {A,B};
- find_start_point([{A,B},{C,D}|Points]) ->
- if (A < C orelse B < D) -> find_start_point([{A,B}|Points]);
- (A >= C orelse B >= D) -> find_start_point([{C,D}|Points])
- end.
- main() ->
- {ok,File}=file:open("test4",read),
- {ok,Prom}=file:read_line(File),
- [Count,_]=string:split(Prom,"\n"),
- {ok,Bin}=file:read_file("test4"),
- [First|Pairs]=binary:split(Bin,[<<"\n">>],[global]),
- Data=parse_bin(Pairs,[]),
- file:close(File),
- main(lists:reverse(Data)).
- main(Points) ->
- StartPoint=find_start_point(Points),
- io:format("~s~n",[concave(sort_list(StartPoint,Points))]).
- parse_bin([],List) -> List;
- parse_bin([Pair|Tail],List) ->
- if Pair == <<>> ->
- parse_bin([],List);
- Pair /= <<>> ->
- [A,B]=binary:split(Pair,[<<" ">>],[global]),
- parse_bin(Tail,[{binary_to_integer(A),binary_to_integer(B)}|List])
- end.
- concave([{_,_},{_,_}|Tail]) -> no.
- concave([{A,B},{C,D},{E,F}|Tail]) ->
- Rot=rotate({A,B},{C,D},{E,F}),
- if Rot>0 -> yes;
- Rot<0 -> concave([{C,D},{E,F}|Tail]);
- Rot ==0 -> concave([{C,D},{E,F}|Tail])
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement