5 kyu

Closest Neighbouring Points I

125 of 146raulbc777
Description
Loading description...
Fundamentals
Mathematics
Data Structures
Algorithms
  • Please sign in or sign up to leave a comment.
  • heliogabalus799 Avatar

    How can you know the order required?? My solutions are identical, the points are just ordered differently.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • ejini战神 Avatar

    Description should be language-agnostic

  • ejini战神 Avatar

    Ruby

    • 3.0 should be enabled with unnecessary logs removed

    • Parameter name should be snake_case

  • ejini战神 Avatar

    Python

    • New test framework should be used with unnecessary logs removed

    • Parameter name should be snake_case

  • ejini战神 Avatar

    Your code should be able to process lists of points up to 1000 length in the allowed runtime for tests.

    But Python tests up to 700 while Ruby tests up to 400

  • FArekkusu Avatar

    Python 3 should be enabled.

  • anter69 Avatar

    This comment has been hidden.

  • KenKamau Avatar

    This comment has been hidden.

  • arne21 Avatar

    Even although the first sentence calls for an accurate solution, many current solutions, including the one with most "best practices" upvotes (4), will fail the following test case, which I think should be added to rule out the not-quite-right solutions:

    test.it("is accurate ;-)")
    listPointsA = [(0,0),(2665,4242),(6397, 7584)]
    resultsA = [3, [[(2665, 4242),(6397, 7584)]], 5009.6695] # note that 5009.6695 is also the rounded distance of (0,0),(2665,4242)
    test.assert_equals(closest_points(listPointsA), resultsA)
    
  • Voile Avatar

    Approved

  • zebulan Avatar

    Minor description rewrite, fixed a spelling mistake, changed name of variable to list_points and added some spacing for readability:

    Description:

    We need a function, closest_points() that may give an accurate result to find the closest pair or pairs of points that are contained in square areas of size l. The function will receive a list of variable number of points in a list (each point represented with cartesian coordinates) and should display the results in the following way [(1), (2), (3)]

    (1) - Number of points received

    (2) - Pair or pairs of closest points in a sorted list of tuples (each tuple having the cartesian coordinates (x, y) of the encountered closest points)

    (3) - the distance of this pair or these pairs of found closes points, that is the minimal distance between every possible pair of the given of points. This value will be expressed as a float with at most, 4 decimal digits (rounded result).

    Let's see some cases.

    l (size of square containing the points) = 10
    list_points = [(5, 10), (3, 6), (1, 4), (6, 2), (4, 3), (0, 4), (10, 3), (9, 1)]
    closest_points(list_points) ---------> [8, [[(0, 4), (1, 4)]], 1.0] # 8 given points, [(0, 4), (1, 4)] is the pair of points with minimal distance (1.0)
    
    l = 20
    list_points = [(8, 14), (16, 5), (5, 5), (15, 18), (17, 10), (0, 14), (4, 15), (19, 17), (13, 16), (10, 18), (14, 13), (12, 14), (11, 15), (7, 15)]
    closest_points(list_points) -------> [14, [[(7, 15), (8, 14)], [(11, 15), (12, 14)]], 1.4142]
    /// Now list_points has 14 points, we can find two pairs of points [(7, 15), (8, 14)] and [(11, 15), (12, 14)] that have the minimal possible distance, 1.4142
    

    Your code should be able to process lists of points up to 1000 length in the allowed runtime for tests.

    Happy coding!!