Ad
  • Default User Avatar

    I made this a long time ago. But if I remember correctly, the distance from from cell 1 to cell 2 must always be computed not by abs(x2-x1) + abs(y2-y2) but instead more precisely with pythagorean's theorem sqrt((x2-x1)^2 + (y2-y1)^2)

    Using this formula, the distance of the three spaces in your example from the target or start would be 2, ≈1.41, and 2.

    So if i remember the kata correctly, the correct answer is the middle one of those three or (1,1) because it is the closest box within the circle of radius = 2 to the target box (2,2)

  • Custom User Avatar

    I don't understand. Take a look at the following setting :

    \begin{matrix}
    \circ & \circ & \times & \circ & B \\
    \circ & \circ & \circ & \times & \circ \\
    \circ & \circ & A & \circ & \times \\
    \circ & \circ & \circ & \circ & \circ \\
    \circ & \circ & \circ & \circ & \circ
    \end{matrix}
    

    where $A$ is where you start from and $B$ is the target cell. The cells with the cross $\times$ inside are all equally distant from the target. This means the kata is not consistent as it assumes that there can be only 2 equidistant cells. Am I missing something ?

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Sample test contains an incorrect test case that doesn't appear in the actual tests:

        it("should return two solutions in some situations", function()
      areSimilar({-1, 0}, {0, -1}, moveMaker(-2,-2,4,8)) end)
    
  • Default User Avatar

    all single digits are narcisitic because anything to the first power is equal to itself or
    x^1 = x

    7 is narcisitic because of the following.
    7 has one digit so I sum that one digit raised to the first power

    start = 7  
    sum = 7^1  
    print (start == sum)
    -- true
    

    for comparison

    start = 20
    sum = (2^2 + 0^2)
    print (start == sum)
    -- false
    
  • Default User Avatar

    IDK what language you are using, but are you taking a string and seperating the characters into an array of numbers?

    If so, then your numbers may be encoded as ascii numbers and are being turned into their integer equivalents, which would explain the constant shift.

    With so little information, and no code to read, that is all I can guess about.

  • Default User Avatar

    Sorry, I meant to point out that you can recompute the sqrt every time you find a divisor to further shrink the iteration count. See my solution.
    While figuring out how to format my critique, I think I forgot the reason I started writing it, and ended up spewing some nonsense.
    I'm not very good at giving advice or tips or knowing when to give any, and would love any input on how to improve.

    Sent from my IPhone

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Because what kind of language would have built in to hex functionality? ;p

  • Default User Avatar

    Your solution for median time is really cool. I simply halfed it and then floored one and ceiled the other, which isn't as cool as your solution. I also like the way you do format strings, putting parethesis around a string and then calling format with it. I think it looks nicer than string.format("")

    If there was one thing I would change it is that you don't store the size of times. You only need to calculate it once since you don't change its size after you fill it. You used #times in 5 different places without the size ever changing. You could have used it once and put it in a variable, and then used the variable.

    The other thing I really liked about your solution was how you added the sums together while retrieving them so that you could calculate the mean without a seperate for loop for adding all the sums together.

    One thing I didn't like so much was that you used times\[#times+1] = time instead of table.insert(times, time)

    The last thing that I thought you did better was put the format function outside of the main function, I put it inside, meaning I was recreating the format function with every call of the main function.