Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 1.00 KB | None | 0 0
  1. %%%-------------------------------------------------------------------
  2. %%% @author przemek
  3. %%% @copyright (C) 2020, <COMPANY>
  4. %%% @doc
  5. %%%
  6. %%% @end
  7. %%% Created : 3. kwi 2020 12:58
  8. %%%-------------------------------------------------------------------
  9. -module(parcellockerfinder).
  10. -author("przemek").
  11.  
  12. %% API
  13. -export(getRandomPointsToList/1).
  14.  
  15. getRandomPointsToList(N) ->
  16.     [{rand:uniform(10000), rand:uniform(10000)} || _ <- lists:seq(1,N)].
  17.  
  18.  
  19. findDistance({X1, Y1}, {X2, Y2}) ->
  20.   math:sqrt(math:pow(X1 - X2, 2) + math:pow(Y1-Y2, 2)).
  21.  
  22.  
  23. findMyParcelLocker(PersonLocation, LockerLocations) ->
  24.     AllDistances = [{LockerX, LockerY, findDistance(PersonLocation, {LockerX, LockerY} || {LockerX, LockerY} <- LockerLocations],
  25.     [{ClosestX, ClosestY, _} | _] = lists:keysort(3, AllDistances),
  26.     {PersonLocation, {ClosestX, ClosestY}}.
  27.  
  28. findMyParcelLockerForEachPerson(PeopleLocation, LockerLocations) ->
  29.     [{findMyParcelLocker(PersonLocation, LockerLocations)} || PersonLocation <- PeopleLocation].
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement