Ad
  • Custom User Avatar

    In this case, the iterative approach to solving the problem will be correct.
    Recursion will not be enough 12000 ms to process all tests.

    Regarding the operation of portals. I would expand the description to something like this:

    Portal(4, 2);
    0000594 ---> 0594495 ---> 0059535 ---> 0005625 ---> 0000675

    Regarding mirror operation with negative numbers:
    The mirror can work with negative values.
    It just doesn't take into account the "-" sign and will also return a negative value.

    -594 ---> -594495

    Few tips
    It is also worth considering the performance of your internet connection and the speed of your PC.
    Because sometimes it can happen that tests are not performed due to system overload.

    In most operations, it is the numbers that are used.
    So I suggest using unary + when returning a number at each operation to avoid string values.

    For me personally, this kata turned out to be extremely difficult to implement,
    but also gave me much-needed experience in working with some methods.
    Good luck coding!

  • Custom User Avatar

    Добрый день!
    Условия у данной Ката не отражают суть задачи.
    Поэтому решил написать данное пояснение, возможно кому-то поможет не ломать голову.

    1. На самом деле описание следующее:
      У вас есть гипотенуза и катет в прямоугольном треугольнике.
    • est - оцениваемое расстояние от полицейского до дороги (катет в треугольнике) - 1 расчет
    • act - фактическое расстояние от полицейского до дороги (катет в треугольнике) - 2 расчет
      readings - содержит 4ре значения.
      const [[distance1, time1], [distance2, time2]] = readings;
    • distance1 - дистанция от радара до автомобиля (1 замер)
    • time1 - время (1 замер)
    • distance2 - дистанция от радара до автомобиля (2 замер)
    • time2 - время (2 замер)
    • timeDif - (time1 - time) - не может быть отрицательным значением (используется для расчета обоих расстояний
      Есть два подхода, чтобы учесть данное условие:
      Обратите внимание, что ваш код должен быть способен обрабатывать показания, передаваемые в функцию в любом порядке.
      Можно вернуть модуль числа при расчетах или просто изменить порядок элементов массива (distance1 > distance2)

    На всякий случай формула прямоугольного треугольника: (A2 + B2 === C**2) (A/B - катеты) (C - гипотенуза)
    Только нужно не забывать, что нам нужно относительное значение и в километрах в час.

    Good day!
    The conditions of this Kata do not reflect the essence of the problem.
    Therefore, I decided to write this explanation, perhaps someone will help not to break his head.

    1. Actually the description is as follows:
      You have a hypotenuse and a cathetus in a right triangle.
    • est - estimated distance from the policeman to the road (the cathetus in the triangle) - 1 calculation
    • act - actual distance from the policeman to the road (the cathetus in the triangle) - 2 calculations.
      readings - contains 4 values.
      const [[distance1, time1], [distance2, time2]] = readings;
    • distance1 - distance from the radar to the car (1 measurement)
    • time1 - time (1 measurement)
    • distance2 - distance from radar to car (2nd measurement)
    • time2 - time (2nd measurement)
    • timeDif - (time1 - time) - cannot be a negative value (used to calculate both distances).
      There are two approaches to account for this condition:
      Note that your code must be able to handle readings passed to the function in any order.
      You can return the modulus of the number in the calculation, or you can simply change the order of the array elements (distance1 > distance2)

    Just in case, the formula for a right triangle: (A2 + B2 === C**2) (A/B - cathetes) (C - hypotenuse).
    Only we need to remember that we need a relative value and in kilometers per hour.

    P.S. please explain in the problem that you have an angle to the road of 90 degrees (For est and act this is a very good explanation).