Ad
  • Default User Avatar

    this seems to be a recurring theme in many of these kata as of late; saw numerous issues reported and was afraid I would start working on a solution and encounter a test case with a negative number in it, so decided to check discussions before starting just in case.

  • Default User Avatar

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

  • Default User Avatar

    I think the hardest part of this problem is figuring out an algorithm to generate all permutations of a string of any length.

  • Default User Avatar

    I finally figured out a solution. So I do have a check at the start if (snail_map.empty()) which passes over the size 0 matrix. But when it came to a matrix of size 1 it kept throwing out that exception. So I added another check inside to see if the matrix of size 1 is empty as shown below.

    for (int i = 0 + leftRightCount; i < MATRIX_SIZE - rightLeftCount; i++)
    {                    
        if(snail_map[leftRightCount].empty()) { return result; }
        result.push_back(snail_map[leftRightCount].at(i));          
        bTraversed = true;
    }
    

    That was the only line of code I added to get the program to work through the Codewars test.
    EDIT: So I just reread the description and I guess my smooth brain didn't pick up on the hint at the bottom about how the 0x0 matrix is represented. Seriously though, I think it would make more sense to say a 1x0 matrix because the way most people understand NxN is [the number of vectors]x[the number of ints in a vector].

  • Custom User Avatar

    there is a check earlier in the code to confirm the array provided is not empty

    Looking at your code, that check seems to happen too late. Why not take care of this case at the start of function?

  • Custom User Avatar

    It's most probably an exception thrown by at, when i is out of range of whatever the snail_map[leftRightCount] is. snail_map is not empty, but snail_map[leftRightCount] is smaller than i.

  • Default User Avatar

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

  • Default User Avatar

    More of a snake than a snail if you ask me

  • Default User Avatar

    words can't describe how I feel after refactoring my code at least four times over 3 days to arrive to pretty much this answer.

  • Default User Avatar

    Probably due to the time complexity of your solution. I'm currently working on this kata and came up with a solution that works, but it takes too long after trying 100000! and 1000000000!. So, got to figure out a more efficient way to code the solution now.

  • Default User Avatar

    If you have an IDE for java set up, you can make a test case like {2, 2, 2, 6, 6} or {2, 2, 2, 3, 4}, step through your code, and look for what goes wrong causing the result not to equal 200.

  • Default User Avatar

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

  • Default User Avatar

    I'd say it does provide all the info it needs when it says assume the roman numerals will always be valid inputs. So you have to make a solution that handles every possible combination of roman numerals - and as already mentioned you probably will have to research sometimes to learn the ins and outs of a topic that you are not necessarily knowledgeable in when coding e.g. if you were doing game programming you may need to do some research on physics formulas depending on what you are trying to do.

  • Default User Avatar

    I find the description for what is valid in this kata not specific enough. I thought of a scenario where "[][()]" could be an input and can only assume it would be valid since it is a combination of the first two listed valid examples.

  • Default User Avatar

    Oh, I like this solution. It changes the char 'c' to lower case and confirms its value is within 'a' to 'z'. Then it gets the numeric value of the char, subtracts 'a' from it (since each letter's numerical value sequentially follows), and then adds 1 to satisfy the requirement of the kata (since a-a=0 or z-a=25).

  • Loading more items...