Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
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.
Java
This is a nice simple kata, but has some issues with the test cases:
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.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!
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 of491
... but a quick check with a calculator shows that the sum of all entries inls
is473
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?My mistake - changed the value of the pointer assigned by
calloc()
before returning it, thus causingfree()
to crash.Now I know that I shouldn't do that!
The testing code for C seems to be buggy.
The 1st test passes okay, the 2nd test gives me this error message:
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!
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:
thirt
, so there's no need to calculate them every time - you can store the literal values as constants.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.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 :)
Yoursolutionisgoodbutyourcodewouldbeeasiertoreadwithmorespaces.
Also, the inner while loop would be more readable if it were indented.
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!)
This comment is hidden because it contains spoiler information about the solution
How did this work? The helper functions have no bodies...
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Loading more items...