Ad
  • Custom User Avatar
  • Custom User Avatar

    Thank you, I thought that distance should be calculated as cell-by-cell path, and sorry for wrong mark:)

  • Default User Avatar

    Your calcPathDistance() function is incorrect: it does not correctly calculate the Euclidian distance between two points for some coordinates. If you want to convince yourself of it, try an online tool like GeoGebra, place two points on [0, 4] and [5, 1] and measure the distance; it is ~ 5.830, not ~ 6.2.


    Please note that you should use the question tag to ask for help, not issue. If there was such a gross mistake in the reference solution, users would have noticed it by now.

  • Custom User Avatar

    Hey, it's me again:) Sorry for disturbing, but i have one more suspision about reference algorithm correctness. Here is the deal:

    requestedDirectionsTo: 'S'

    Village map:

      [ ' ', ' ', ' ', ' ', ' ' ],
      [ ' ', ' ', ' ', ' ', ' ' ],
      [ ' ', ' ', ' ', ' ', ' ' ],
      [ ' ', ' ', ' ', ' ', ' ' ],
      [ ' ', ' ', ' ', ' ', ' ' ],
      [ ' ', 'S', ' ', ' ', ' ' ],
      [ 'S', ' ', ' ', ' ', 'S' ],
      [ ' ', ' ', ' ', ' ', 'S' ]
    

    Reference solution:

      [ '↘', '↓', '↙', '↙', '↙' ],
      [ '↘', '↓', '↙', '↙', '↙' ],
      [ '↘', '↓', '↙', '↙', '↓' ],
      [ '↘', '↓', '↙', '↙', '↓' ],
      [ '↘', '↓', '↙', '↙', '↓' ],
      [ '→', 'S', '←', '↘', '↓' ],
      [ 'S', '↑', '↖', '→', 'S' ],
      [ '↑', '↖', '→', '→', 'S' ]
    

    My solution:

      [ '↘', '↓', '↙', '↙', '↓' ],
      [ '↘', '↓', '↙', '↙', '↓' ],
      [ '↘', '↓', '↙', '↙', '↓' ],
      [ '↘', '↓', '↙', '↙', '↓' ],
      [ '↘', '↓', '↙', '↙', '↓' ],
      [ '→', 'S', '←', '↘', '↓' ],
      [ 'S', '↑', '↖', '→', 'S' ],
      [ '↑', '↖', '→', '→', 'S' ]
    

    Distances map:

      [ '5.4', '5.0', '5.4', '5.8', '6.0' ],
      [ '4.4', '4.0', '4.4', '4.8', '5.0' ],
      [ '3.4', '3.0', '3.4', '3.8', '4.0' ],
      [ '2.4', '2.0', '2.4', '2.8', '3.0' ],
      [ '1.4', '1.0', '1.4', '2.4', '2.0' ],
      [ '1.0', '0.0', '1.0', '1.4', '1.0' ],
      [ '0.0', '1.0', '1.4', '1.0', '0.0' ],
      [ '1.0', '1.4', '2.0', '1.0', '0.0' ]
    

    Difference between solutions in [0,4] and [1,4]. Let's take [0,4] for example, in ref solution it points to keyPlace [5,1] with distance 6.2, in my solution it points to keyPlace [6,4] with distance 6.0, why so? Thank you for your help:)

  • Custom User Avatar

    Oh, now I'm understanding this, thank you)

  • Custom User Avatar

    [3, 2] has the same distance to [2, 0] as to [1, 3], [1, 3] has the lowest row index, so choose that one to point to.

  • Custom User Avatar

    It seems that current solve implementation is not assigned with task conditions.

    "In case of a tie, prefer the location with lowest row index.
    If there still is a tie, prefer the location with lowest column index."

    Here is an example that generated as random test for me:

    Village map:

    [ ' ', 'T', ' ', ' ', ' ' ],
    [ '#', ' ', ' ', '#', 'T' ],
    [ '#', ' ', ' ', ' ', ' ' ],
    [ ' ', 'T', ' ', ' ', ' ' ]
    

    requestedDirectionsTo: #

    Reference solution:

    [ '↓', '↙', '↘', '↓', '↙' ],
    [ '#', '←', '→', '#', '←' ],
    [ '#', '←', '↗', '↑', '↖' ],
    [ '↑', '↖', '↗', '↑', '↖' ]
    

    My solution:

    [ '↓', '↙', '↘', '↓', '↙' ],
    [ '#', '←', '→', '#', '←' ],
    [ '#', '←', '↗', '↑', '↖' ],
    [ '↑', '↖', '↖', '↑', '↖' ]
    

    Distances map:

    [ '1.0', '1.4', '1.4', '1.0', '1.4' ],
    [ '0.0', '1.0', '1.0', '0.0', '1.0' ],
    [ '0.0', '1.0', '1.4', '1.0', '1.4' ],
    [ '1.0', '1.4', '2.4', '2.0', '2.4' ]
    

    Look at the cell [3, 2], it has 2 cells around with distances 1.0 ([2, 1] and [2, 3]), but reference solution prefer cell with higher column index.

  • Default User Avatar

    Hello. The function returns a single location, but a bug report reports that 2 positions have been received. console.log() shows return value. Is it possible that task verification has a problem?
    http://joxi.ru/12M8zyBH00qMdm