Ad
  • Custom User Avatar

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

  • Custom User Avatar

    I know I'm 2 years late, but I saw your comment and noticed you still don't have a solution.

    I found it helps to understand the algorithm if you do some examples by hand.
    If you encode "Mellow Yellow" and "Melllow Yelow" by hand, you should see a difference.

  • Custom User Avatar
  • Custom User Avatar

    This is a nice simple kata, but has some issues with the test cases:

    1. (major) Some solutions use one int variable to track both the east/west difference and the north/south difference. Such solutions would fail to either "eeeeennnnn" or "eeeeesssss" but have passed. For this reason, you need to test specifically for walks of the correct length which place you at a wrong spot directly north-east (or north-west, south-east, south-west) of the start.
    2. (minor) Some ridiculously long walks in the test cases could encourage more efficient solutions - some don't check the walk's length until they've scanned through the whole array to check the destination!
    3. (minor) Some random tests would be nice too.
  • Custom User Avatar

    Although this code passed the tests, it shouldn't have: Go 5 blocks north, then 5 blocks east and we're not where we started but this code says we are!

  • Custom User Avatar

    Failed tests don't display any output making debugging very difficult.

    So I'm not sure if my own code is at fault or if one of the tests is broken...

    One of the tests seems to have t = 700, k = 6, ls = {73, 73, 74, 81, 85, 87} and expects a result of 491... but a quick check with a calculator shows that the sum of all entries in ls is 473

    Is this really one of the tests? If not, could there be some more helpful output to cout (for the fixed tests at least) so that it's clear what the inputs are for each test?

  • Custom User Avatar

    My mistake - changed the value of the pointer assigned by calloc() before returning it, thus causing free() to crash.

    Now I know that I shouldn't do that!

  • Custom User Avatar

    The testing code for C seems to be buggy.
    The 1st test passes okay, the 2nd test gives me this error message:

    *** Error in `/home/codewarrior/solution': free(): invalid pointer: 0x000000000107d671 ***
    

    If I switch the order of the tests, then the test which had been 2nd passes and the test which had been 1st results in the error message!
    This suggests that there's something amiss about the way that free() has been used...

    Please fix this, as I can't complete the kata otherwise!

  • Custom User Avatar

    Welcome to CodeWars!
    I hope your time here is enlightening.

    That's quite a piece of code you have there - it looks like it took some time to write and I commend you for keeping track of all the variables whilst writing it.
    (Well done for remembering to allocate and free memory for the array of remainders too.)

    I have a few points of advice for you to bear in mind for future coding... hope they help:

    1. The remainders (1, 10, 9, 12, 3, 4) were given in the problem text. They're always the same for every application of thirt, so there's no need to calculate them every time - you can store the literal values as constants.
    2. One of the principles of writing good code is DRY - don't repeat yourself. If you find that you're repeating yourself (or even copy-pasting your own code), ask yourself "do I really need to use the same code again?" If you really do, then it's usually best to write a seperate "helper" function to do the work. It's less typing, less code to change if things go wrong and usually much clearer.
    3. Variable names should usually be as descriptive as possible. Generic names like new_number can be fine (I'd be a hypocrite if I said never to use them!), but if your code is more than about thirty lines, generic names make it hard to keep track of what each variable is supposed to be.
    4. Another help in long code is comments. Even a one line explanation of what each loop is doing can clarify code enormously.

    If any of this seems abstract, take a look at the solutions of other code warriors.
    Ask yourself "If I needed to modify someone else's code to solve a slightly different problem, which code would make it easiest?"
    Then try to write similar code yourself.

    Practice makes perfect :)

  • Custom User Avatar

    Yoursolutionisgoodbutyourcodewouldbeeasiertoreadwithmorespaces.

    Also, the inner while loop would be more readable if it were indented.

  • Custom User Avatar

    I have mixed feelings about this solution...

    On the one hand, it's elegant, concise and uses reduce with an anonymous function — all my favourite things!

    On the other hand, what if we have a billion elements in the list and the missing element is the second one?
    The best case performance of the algorithm is exactly the same as the worst case!

    Voted clever for elegance. (imho people who voted Best Practice need a lesson in algorithmics!)

  • Custom User Avatar

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

  • Custom User Avatar

    How did this work? The helper functions have no bodies...

  • Custom User Avatar

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

  • Custom User Avatar

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

  • Loading more items...