Ad
  • Custom User Avatar

    e1 += e2 translates into e1 = (T) (e1 + e2), where T is a type of e1. In this case, the implicit cast crops double into int, which might lead to a not-very-easy-to-find bug:
    int num = 1;
    double d = 9999999999d;
    num += d;

  • Custom User Avatar

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

  • Custom User Avatar

    if the str starts with ")" there is no need to continue: the answer is known.

  • Custom User Avatar

    Yeah I thought I speak for myself all the time (didn't I? Who did I speak for from your point of view?)
    I had some strange feeling about this kata in the beginning, after executing the java version test as-is I got: ./src/test/java/BagelTest.java:9: error: incompatible types: BagelSolver.Bagel cannot be converted to Bagel
    Then I went to the discussion to see whether this is a part of a riddle or an issue. On the discussion page, I again got that bad feeling about it. Then after spending some time dealing with the errors, I looked at the solutions and it confirmed my bad feelings about it. I thought it would be nice to write to others that they might be rather frustrated here, while there are more interesting katas out there.

    Good for you that you learned something along the way. But in my opinion this kata has a low ROI: a lot of difficulties to solve and so little as a reward. I believe a lot of people will know a possible solution, but will discard it, because this is something that never exists in good production code. So they would waste quite some time to find another way to solve it. It's like using some anti-pattern such as GOTO, many people know about it, but nobody is going to use it.

    I didn't get the point in the second part. Do you think there should be only comments like: wow, that's just the brilliant kata! I got the fantastic error, the task is pleasantly vague, I really enjoyed the time of struggling to understand what the author meant

  • Custom User Avatar

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

  • Custom User Avatar

    Very strange and weird kata. Basically, this kata tests whether one know what the the mystery function is. Roughly speaking, it is something similar to ask people to write some formulas from the theory of relativity: it's easy when you remember it, and it's highly unlikely that you will be able to come up with a solution in case you haven't studied it.

    In addition, there's no explanation what the inversed function should do, as well as there's no examples for this function. How is one supposed to know what 'mysteryInv' means?

  • Custom User Avatar

    I think the task could be even more clearer. I understand the task as if there could be many smiles in one String, so I've been writing code to count smiles for input String like :-)k :D ;] hello:)

  • Custom User Avatar

    Running time of this solution is quadratic O(n^2), where n is length of array. Functions that iterate through the array are called for each element in the array. At the same time, this problem could be solved in a linear time O(2n). So, I would like to ask: why do we see Best Practices points for this solution? This is a brute force solution, it may be good as an attempt or for testing purposes, but why "Best Practice"?

    I tried to execute this:


    int[] arr = new int[100000001];

    Arrays.fill(arr, 20);

    findEvenIndex(arr);



    Linear time solution gives answer in just 1 second on my computer, this quadratic solution executes forever (I waited for several minutes and stopped it), with input array of length 100000 elements, this solution gives answer in 12 seconds.