5 kyu
Directions Reduction
2,697 of 89,525g964
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
I think this site is not for a beginner like me that knows nothing about coding
First of all, it is not a kata issue.
Maybe you just picked a challenge which is too difficult for beginners? This kata is ranked 5 kyu, which is fairly difficult. Did you try to solve an 8 kyu kata, or a 7 kyu kata?
Maybe this paragraph will clear up some things.
I think you should aim for 8-7 kyu kata first
My code past basic tests but when I submit it, I get this error:
longer explanation available when compiling with
-explain
-- [E006] Not Found Error: src/test/scala/fixture.scala:43:38 ------------------ 43 | case (acc, x) if (acc.last != opposites(x)) => acc :+ x | ^^^^^^^^^ | Not found: oppositesThis is not even my code. My code is in src/main this error is stemming from src/test Did I do something wrong?
I will take a look at this.
This should be fixed, please verify.
I felt like I was moving in circles for a moment.
OCaml function name should be
snake_case
fixed
Please do not change translations and invalidate existing solutions without any discussion. I will revert your changes.
Can someone explain to me why the path ["NORTH", "WEST", "SOUTH", "EAST"] is not reducible even though you end up at the same place? That seems to be the point of this kata
Because opposite directions aren't side by side. Do you end up in the same place? Yes (if the path is plain), but to eliminate them they should be side by side, or after some elimination, become as such, that's a requirement.
Good Point! This combination among other does indeed take you back to the starting point. This idea is worth investigating. However, the purpose of this practice is to only eliminate unnecessary moves being in opposite direction to avoid redundency in the path sequence/.
This comment has been hidden.
This comment has been hidden.
Under sample tests, this test check is invalid: a = ['NORTH', 'NORTH', 'EAST', 'SOUTH', 'EAST', 'EAST', 'SOUTH', 'SOUTH', 'SOUTH', 'NORTH'] test.assert_equals(dir_reduc(a), ['NORTH', 'NORTH', 'EAST', 'SOUTH', 'EAST', 'EAST', 'SOUTH', 'SOUTH'])
Should return ['EAST', 'EAST', 'EAST', 'SOUTH'] and not ['NORTH', 'NORTH', 'EAST', 'SOUTH', 'EAST', 'EAST', 'SOUTH', 'SOUTH'] as shown in the test.
Please should confirm!
The test is fine, read the description again.
This comment has been hidden.
The cause of your problem is the fact that your code mutates
arr
, and the changes you make to it destroy the data which is later used by tests to verify your result. Unfortunately, for some reason beyond my understanding, the solution function accepts the input as a non-const reference, and any mutation turns out to be destructive. You can resolve your issue by either making a copy ofarr
in your solution, or changing the function signature to acceptarr
by value or by const reference.I will fix the setup of the challenge and change the function signature some time soon, but I cannot give any ETA for that.
Additionally, in some cases your call to
is_pair(*start, *(start + 1))
seems to read past the end of the arr.Thank you, Making a copy of
arr
did the trick.It might help, but notice that your soltion still crashes in one of ~five runs. Apparently, mutating the array only emphasized some other bug sitting somewhere there.
Following test cases seem invalid;
Please check other random test cases as well...
You misunderstand the task.
The correct answer to the
Fixed Test
you showed is{"NORTH","WEST","SOUTH","EAST"}
, because there are no consecutive opposite directions to reduce.Then the task explanation needs updation... if i follow {"NORTH","WEST","SOUTH","EAST"}, i am wasting my energy because it will bring me to the same point. The sequence doesn't matter...
What update would you suggest? Because the description tells you MULTIPLE times about this quality to the kata task.
Going to one direction and coming back the opposite direction
right awayis a needless effort.
You can immediately see that going "NORTH" and
immediately"SOUTH" is not reasonable, better stay to the same place!
"NORTH" and "WEST", "WEST" and "SOUTH", "SOUTH" and "EAST" are not
directly oppositeof each other and can't (be reduced).
And for that matter very test case we're talking about is literally discussed directly in the
Notes
section.Point # 3 doesn't make sense, logically & practically. Just having 2 non-opposite directions adjoining to eachother, doesn't reduce their effects overall unless you have distance in the play.
It makes perfect sense, if you don't start making up your own rules. You need to follow the rules of the kata, not what you believe. "distance", as you desribe it, is irrelevant here.
But isn't it more logical to cancel out everything even if it's not directly opposite? If 'NORTH, WEST, SOUTH, EAST' brings you to the same spot, why does tha kata request to not remove anything (because it's not directly opposite)? I'm just curious, as if I was to build a similar function in the future, I would do it my way
I agree that the
{"NORTH","WEST","SOUTH","EAST"}
case should just return an empty array. The problem I think, is that the theme (I guess?) of the kata doesn't quite match the actual logical problem it's asking. Hopefully that makes sense...So far all exercises were cool. This one however - just horrible!
What if get NORTH-NORTH-SOUTH-SOUTH? So this would not be "needless directions"?
It makes no sense! The worst thing is that it is explained in length, using words and metaphors as if it is intended to make sense - but it does not!
It takes too long to explain a silly exercise that makes no real logical sense. PASS
This comment has been hidden.
No, it shouldn't and that case is explained in the kata's description. Read it again. Not a kata issue.
This comment has been hidden.
Poorly designed/explained Kata.
This comment has been hidden.
It requires Node v20, not currently available in CW. Not a kata issue.
This comment has been deleted.
it gives ["NORTH", "WEST", "SOUTH", "EAST"] for every test
in fixed_tests
for directions: {"NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"}
expected: {"WEST"}
but in random_tests
for directions: {"NORTH", "WEST", "SOUTH", "EAST", "SOUTH", "NORTH", "EAST", "SOUTH", "WEST"}
expected: {"NORTH", "WEST", "SOUTH", "EAST", "EAST", "SOUTH", "WEST"}
I'm confused...
Shouldn't the expected result in fixed_tests equal {"SOUTH","NORTH","WEST"}?
edit: I just had a sudden realization. Thank you for your explanations.
Could someone explain me why ['NORTH', 'NORTH', 'EAST', 'SOUTH', 'EAST', 'EAST', 'SOUTH', 'SOUTH', 'SOUTH', 'NORTH'] should equal ['NORTH', 'NORTH', 'EAST', 'SOUTH', 'EAST', 'EAST', 'SOUTH', 'SOUTH'] and not ['EAST', 'EAST', 'EAST', 'SOUTH']. I am a beginner in english and at coding so please say it as simple you can.
Because you can eliminate opposite directions only if they are next to each other. Check the Other examples part of the description.
Thank you.
Why ["NORTH", "WEST", "SOUTH", "EAST"] should equal ["NORTH", "WEST", "SOUTH", "EAST"], not []?
Because it has no adjacent steps which would immediately cancel out each other.
Why I can't return ['NORTH', 'EAST'] instead of ['EAST', 'NORTH']????????? And why ['NORTH', 'NORTH', 'EAST', 'SOUTH', 'EAST', 'EAST', 'SOUTH', 'SOUTH'] better than ['SOUTH', 'EAST', 'EAST', 'EAST']????????
Because the order is different? You need to respect the initial order of elements, and remove some of them if possible, not rearrange it as you see fit.
["NORTH", "EAST", "NORTH"] expects ["NORTH", "EAST"] why not ["NORTH", "EAST", "NORTH"]?
IMO, you are reading the logs wrong.
Actual should equal Expected
-->["NORTH", "EAST"]
should equal["NORTH", "EAST", "NORTH"]
OP solved it, closing.
The c++ test case appears to not work. I'm pasting the error I got bellow. I figured I'd post.
/tmp/main-cc53e9.o: In function
dirReduc_Tests::Fixed_Tests()': main.cpp:(.text._ZN14dirReduc_Tests11Fixed_TestsEv[_ZN14dirReduc_Tests11Fixed_TestsEv]+0x21d): undefined reference to
DirReduction::dirReduc(std::vector<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::__cxx11::basic_string<char, std::char_traits, std::allocator > > >&)' main.cpp:(.text._ZN14dirReduc_Tests11Fixed_TestsEv[_ZN14dirReduc_Tests11Fixed_TestsEv]+0x63b): undefined reference to `DirReduction::dirReduc(std::vector<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::__cxx11::basic_string<char, std::char_traits, std::allocator > > >&)' clang: error: linker command failed with exit code 1 (use -v to see invocation)You did not define the method correctly.
Not a kata issue.
instructions unclear, im on mars
This comment has been hidden.
That's because the
dirReduc(arr)
there is not returned, so the function didn't return anything and therefore results inundefined
.This comment has been hidden.
This comment has been hidden.
In Python the directions are all uppercase, like
"SOUTH"
.["SOUTH", "SOUTH"]
can't be reduced.I am confused by the question if it says North East South West My code doesn't have to change anything right?
Correct.
Thanks.
This comment has been hidden.
Not good, you are modifying the input array, your inner-loop can also be replaced with a dict lookup + conditional statements, happy coding !
Thank you for your answer, that's helping me a lot!
This comment has been hidden.
The problem is not with the section of code that you quoted, the problem is with your
areOpposite
function. You are summing the first letter of each direction to see if they are opposites, but this doesn't really work because two possible direction combinations sum to the same number. Manually check'N' + 'N'
and'W' + 'E'
, and you should see what I mean. In this case, anytime yourareOpposite
function is called forNORTH
andNORTH
, it will returntrue
, which is not what you want.Yeah, should have checked that earlier. Thanks
I don't know how this problem ended up in 5 kyu, I only know that I spent more time on the reading conditions than on the solution process
This comment has been hidden.
usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/cmath:421:11: error: no member named 'sin' in the global namespace using ::sin;
stderr looks like this but multiplied until infinity ^
Just tried the kata in C++, and no. That's not an error from the tests.
Which part of this is an issue from the kata? 🤔
I don't see any error in the kata passed by more than 3000 people.
I think this questions is stupid how is this possible?
a=["NORTH", "WEST", "SOUTH", "EAST"] test.assert_equals(dir_reduc(a), ["NORTH", "WEST", "SOUTH", "EAST"])
How do you get this result? If you are given these instructions, then taking these directions will lead you to the same spot you were before. I get the question but if the purpose is to avoid redundancy then what is more redundant than being end up in the same spot?
That is if the task is to reduce the steps to the most optimal.
The actual task is:
From,
NWSE
. There's noWE
,EW
,SN
, orNS
. Which means, you don't need to reduce it.It is not stated that they need to be in sequence or out of sequence, in some cases the result considers directions that aren't in sequence but somehow dont reduce this occurance
Bro it is stated it should be in a type of sequence you can understand the condition by the below example. for example [North,East ,West, South] then since east west are in sequence they are eliminated first -> The Array is reduced as [North South] Again North South are in sequence so the will be eliminated so Final result is An empty array
This kata melted my brain. Why is it so hard I gave up 😭😭😭😭😭😭
{"NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"} According to the instructions, NORTH followed immediately by SOUTH cancels out, and vice versa. Same case for WEST and EAST. Thus the nett result is SOUTH, NORTH, WEST. Then why is the result expected just WEST?
...
ooh.. i get it. it plays by tetris logic.
Because the result SOUTH, NORTH, WEST still has the opposite pole next to each other, i.e SOUTH, NORTH. It is also mentioned in the description towards the end. I hope this helps.
This comment has been hidden.
Your code is wrong and has an infinite loop, it fails the 3rd sample test. Please read this: https://docs.codewars.com/training/troubleshooting#post-discourse and mark your post as having spoiler content next time.
This comment has been hidden.
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting#print-input
Manage to finish. I must refactor my code to acomodate to new knowledge that you will only get from the testing parameter, why not just incorporate this one example { "NORTH", "WEST", "SOUTH", "EAST" } to the description?
Because it's already there at the end of it.
ah yes, thanks!
Seems some people missed the same thing as I did, the words "right away".
In this sentence =>
"Going to one direction and coming back the opposite direction right away is a needless effort."
This means that its only adjecent directions in the array that should be checked if they are needed or not.
So:
W - E - S => S
W and E cancels out, not needed and adjecent.
BUT
W - S - E => W - S - E
Here S is between W and E, so they do NOT cancel out. W and E are not adjecent and are therefore not "...oposite direction right away..."
I had the answer correct but the order is wrong, I think they should accept these type of stuff (Javascript)
for ["EAST","EAST","WEST","NORTH","WEST","EAST","EAST","SOUTH","NORTH","WEST"] : expected [ 'NORTH', 'EAST' ] to deeply equal [ 'EAST', 'NORTH' ]
or ["NORTH","SOUTH","EAST","WEST","SOUTH","NORTH","EAST","SOUTH","WEST","EAST","SOUTH","NORTH","WEST","EAST"] : expected [ 'SOUTH', 'EAST' ] to deeply equal [ 'EAST', 'SOUTH' ]
No, while you end at the same place, the path is different.
This comment has been hidden.
It is not reasonable to make such an assumption when the kata has been solved more than 70k times. You should read more carefully the description.
This comment has been hidden.
I'm having a problem with the tests, it throws this error: Expected: equal to [ "NORTH", "WEST", "SOUTH", "EAST" ] Actual: [ ]
But isn't the point of the kata to "cancel" the Nort, South, West, East?
The
ISSUE
label is for provable kata issues. Please use theQUESTION
label when asking questions. See https://docs.codewars.com/training/troubleshooting#post-discourse.The example
["NORTH", "WEST", "SOUTH", "EAST"]
is explained in the description.Not a kata issue.
Same
have same issue
My programm offers shorter way than results
This comment has been hidden.
Way too easy for 5kyu
python new test frame work
Approved
Ruby:
3.0 should be enabled
function name should use
snake_case
done
C#: method name should be
PascalCase
(Please refer to implementation of backward compatibility here )Random tests for submission seem to be broken in Python
If you can't prove and supply specific examples of any kata code error, then you should not post as an
issue
, post instead as aquestion
.Your code is incorrect, not passing many fixed tests, let alone random tests.
Story about the Wild West which we deserve
Mega weird kata. He focused to write the story about wild west, but forgot to focus on explaination. L
Having problems with random tests in TypeScript. For example: Log [ 'SOUTH', 'NORTH', 'NORTH', 'NORTH', 'SOUTH', 'WEST', 'SOUTH', 'EAST', 'EAST' ] [ 'EAST' ] expected [ 'EAST' ] to deeply equal [ 'NORTH', 'WEST', 'SOUTH', …(2) ]
Not a kata issue. See https://docs.codewars.com/training/troubleshooting/#post-discourse.
This comment has been hidden.
There are two bad test conditions. One does let [N, S, E, W] be reduced to []. This is nonsense. Those are directions that lead back home. Specifically the worst case of the problem you're trying to solve.
Another does not pass because the order is incorrect in the output. This is also a bad test case as all sets of directions are transpoisitonal. Going [N, N , W, W] is the same as going [W, N, W, N] or [W, N, N, W]. You always end up at x: -2, y: 2.
This comment has been hidden.
[ 'NORTH', 'NORTH', 'NORTH' ]
One of my results was as follows:
['EAST', 'EAST', 'EAST', 'SOUTH'] should equal ['NORTH', 'NORTH', 'EAST', 'SOUTH', 'EAST', 'EAST', 'SOUTH', 'SOUTH']
However, reasoning about the answer shows that my answer (on the left) is further reduced than the right answer. Both 'North' items are cancelled out by two of the three 'South' items, reducing to my answer. The answer cases don't seem to be fully reduced.
Read the description again, you can only reduce two directions if they are next two each other and are opposites, or if after reducing they become next to each other and are opposites.
Weird. The answers match the final tests, but still throws an error???
Because that's not always the case:
Your code isn't reducing the path sometimes.
"Not all paths can be made simpler. The path
["NORTH", "WEST", "SOUTH", "EAST"]
is not reducible."NORTH"
and"WEST"
,"WEST"
and"SOUTH"
,"SOUTH"
and"EAST"
are not directly opposite of each other and can't become such. Hence the result path is itself :["NORTH", "WEST", "SOUTH", "EAST"]
."This is false because you'd end up back where you started.
Exactly what I thought. It makes no sense. I'm not attempting to this kata for this reason
This kata is weird.
I used x and y coordinates to determine the destination and then used those to simply return the most optimal route.
Example:
x: -1 y: 1
would be once WEST and once NORTH.The input array was:
['EAST', 'NORTH', 'SOUTH', 'NORTH', 'WEST', 'NORTH', 'SOUTH', 'NORTH', 'SOUTH', 'WEST']
The expected answer is:
['EAST', 'NORTH', 'WEST', 'WEST']
when in reality
['NORTH', 'WEST']
would be the most optimal and time saving route.So now I have to wonder how to get a less optimal solution to fit the weird dependencies of this kata...
The kata doesn't say that the requirement is to create the most optimal route. It asks you to create the simplified version of the route:
I get that the description says 'right away', so you're only supposed to cancel out immediately adjecent opposites. However that makes no sense as the description also says
which clearly sounds like an optimization. Especially the last example in the description
["NORTH", "WEST", "SOUTH", "EAST"]
makes no sense why it shouldn't be reduced to[]
. If you simply follow these instructions as the early settler you would literally end where you started and I'd be pretty upset about the worthless effort 😂My code keeps timing out when I try to use the .lower() function, does anyone know why this could be?
your code remains in your
while
loop because a break condition is never met. you can put a limit on the number of cycles and use aprint
statement for "direct" to see what's happeningThis is the worst problem I've encountered on codewars. Not in difficulty, but in logic. The OP wants you to do this in a certain way, even though it defys logic. Poorly written.
This comment has been hidden.
Your code isn't reducing the path as the instructions says. Read them again. Your code returns
["NORTH"]
for["NORTH", "NORTH"]
for example. Not a kata issue.From the description I understood the task to be removing adjacent opposite pairs in a loop from the list until none remained to remove. But one of the python tests fails with "['SOUTH', 'WEST', 'WEST'] should equal ['WEST']". That seems to make no sense, because SOUTH and WEST are not opposites!
bro why is one of the tests literally ["NORTHNORTH"] ?????? what is the meaning of this
Ngl this one left a bad taste in my mouth. In the end I was like "fuck it I'll just do what is asked of me" but the kata description is just weird. It says that "NORTH, WEST, SOUTH, EAST" is not reducible. At first I was like "wft that just leads you back to the origin" and I got mad. However then I read a comment that said that maybe it wasn't a 2D plane, maybe there are obstacles and stuff that would not necessarily lead you back to the origin. So I was like "ok that kinda makes sense". I think it could use with a better explanation of why it isn't reducible, maybe add some drawings or sth like that. There is a drawing here in one of the comments on why it may not be reducible that you could just add to the explanation.
This comment has been hidden.
still it shouldnt make a difference
This comment has been hidden.
You misunderstood the task - not a kata issue.
In this case the test returns the entire string (["NORTH", "WEST", "SOUTH", "EAST"]), which must be annihilate and equal to [].
Check the tests for JS, please
The tests are correct, you misunderstood the task. Please reread the description.
This comment has been hidden.
I don't understood your explanation, sorry!
"the test suite should always contain a test with a following scenario: for example ..., ..., WEST, EAST, WEST, SOUTH
To ensure that when WEST and EAST are removed the next WEST will not be removed because EAST should be already gone"
This remark may correspond to your solution but there are lots of possible solutions and the random tests are ... random.
I don't consider that it is an issue.
Should pass Random Tests Expected: {} But was: {}
Sorry, I can't see any difference. And my code passed all tests in local.
You passed the kata...
Yeah .... I was stubborn :)
This comment has been hidden.
This comment has been hidden.
There is no "hint" button.
This comment has been hidden.
The description is fine. This isn't a kata issue. If you're a beginner, then don't try to solve a 5kyu kata at first. Start with 8 and 7kyu,it'll save your time and frustration.
nice kata!
I dont really understand the desire output, Is it skipping the opposite cardinals on the new calc or always taking in count it.
made me think
Please learn how to use punctuation before posting a challenge. The description is illiterate.
"illiterate" ?
"NORTH", "WEST", "SOUTH", "EAST": array lengths differed, expected.length=4 actual.length=0; arrays first differed at element [0]; expected: but was:
Why I didn't pass this test? It's circular path or not? And I expected that the result will be reduced to zero( stay at one place)
But that's not what the description is asking for, read it more carefully. This exact example is mentioned too.
If you wanted to cancel "NORTH", it would have to be followed by "SOUTH", but it isn't.
Not a kata issue, use "Question" label when you're not sure.
But it waste of time to move around and to come to the same place! If you thirsty and want to eat =) But I understand your answer and I will fix my code! Thank you! :)
I realize that its been 2 1/2 weeks and you've already solved it, but I thought I'd add my two cents here. Its natural to think of the problem as occuring in a flat and empty plane, but in reality there may be obstacles in one's way that could prevent movement in a direction, or you may be moving along up or down. So, N, W, S and E could, theoretically put you on the other side of a wall or cliff, or directly below where you started. That is why you can only cancel opposites that occur within the same groupings of movements within the same plane that are not interrupted by perpendicular movements. I hope this makes sense!
This comment has been hidden.
This comment has been hidden.
Your code violates the rule where only consecutive opposing directions should be discarded until there is no more consecutive opposing directions left.
everybody should activate Harding-Code Skills to solve this kata
This is the worst task I've ever seen.
This comment has been hidden.
This comment has been hidden.
For what I can see, you are almost done. You just have to think what will happen, let's say, for example, going north twice.
This comment has been hidden.
The logic of your code handles well when it compares NORTH against SOUTH or EAST against WEST (or viceversa), but doesn't when you need to go in the same direction twice in a row. Try to test for those scenarios. Example, you are given this array: |NORTH -> NORTH -> WEST -> WEST|; And compare how it behaves with this other array: |NORTH -> SOUTH -> EAST -> WEST|; Analize the outcome of both.
Thanks! :) I focused my attention on the wrong thing. The output of logs seemed strange, and it still seems so.
This comment has been hidden.
No, they're not. The paths are different, and there are rules about how to reduce the path, so:
Yes, but
["NORTH", "WEST", "SOUTH", "EAST"]
is not reducible. And it's shown in the description.correct, they are same, order is not important. anyone worked with vectors would know that
No, they're not, and order matters in a path. Anyone that worked with a map would know that.
[north, south, west, east] is [], but the first statement is of course, wrong.
@Chrono79, as you said
["NORTH", "WEST", "SOUTH", "EAST"]
is not reducible, am agreebut how's
["EAST", "WEST"]
not the same as the example above?? it's reducible too, isn't it?! why is[]
acceptable not["EAST", "WEST"]
as it is?I don't follow you there:
Going in one direction and immediatly going in the opposite one should be avoided.
Really nice Kata, made me happy to be able to understad the Aggregate function in C# with it, i will see if i can do the same with JavaScript eventually!
I dont know why, but it was really hard to solve) 2 hours did it
I passed the test but it raises an error can you guys please take a look?
Your code fails the second sample test. And that case is explained in the kata's description.
This comment has been hidden.
How is that equal? You're probably not testing it in your IDE with the same input. A problem with your code is not a kata issue.
The first value is your wrong answer, to see the input, print it in the first line of your function.
Result of dirReduc([""]) is [], as it should be, right? Because test says that if input is [''] then result should be empty list.
No, that's not what it says. I don't think there even is a test with
[""]
. This value is what you returned, not the input.This comment has been hidden.
Hi @WalterBlack1 and welcome to Codewars;
Your solution works 99% of the time. It's not failing on ones with empty list input, it's currently failing on inputs like:
['NORTH', 'SOUTH', 'SOUTH', 'EAST', 'WEST', 'NORTH']
where you are returning
['']
when the kata wants[]
. That's the only type of case that's causing you to fail.Since you are new I recommend reading this Troubleshooting page specifically the part about "Printing your input". This allows you to see in console which inputs are causing problems.
So, in Python, all that means is:
thanks a lot for this tip !
I am not sure if this test case is explained in the desription: ['EAST', 'EAST', 'NORTH', 'WEST'] should equal ['EAST', 'NORTH']
I will post exact text from the Details
*Write a function dirReduc which will take an array of strings and returns an array of strings with the needless directions removed (W<->E or S<->N side by side)
----Side BY Side is the main ingredient----
*In ["NORTH", "EAST", "WEST", "SOUTH", "WEST", "WEST"], "NORTH" and "SOUTH" are not directly opposite but they become directly opposite after the reduction of "EAST" and "WEST" so the whole path is reducible to ["WEST", "WEST"].
----Again North and South were cancelled, because East and West are Side By Side----
There are no Side By Side cancellations in ['EAST', 'EAST', 'NORTH', 'WEST']. Please copy and paste the text from the Details that explains this test case
That's the error message, the first value is what your function wrongly returned and the other one is the expected value, print the input to debug your code.
Hey, my code doesn't pass the tests because, sometimes, my commands aren't ordered as in the solution: instead of ["NORTH", "EAST"] my output is ["EAST", "NORTH"]. That shouldn't make any difference though, right?
It does, the path is not the same. Not a kata issue. Only remove the ones you can reduce, keep the order of the others.
This comment has been hidden.
Because that's not what the kata asks.
"Write a function dirReduc which will take an array of strings and returns an array of strings with the needless directions removed"
You forgot that.
Ou, now I got that part of the task right :) Then it's easier than I expected. Thanks!
This comment has been hidden.
Where do you see that? There are no errors in the tests that are the same in all languages (kata passsed by 49 people in Julia out of a total of 66,386).
No, and read the notes:
This comment has been hidden.
Got it! OK, it wasn't clear to me, but I see we can't approach this from a position standpoint now. Thanks for clarifying.
Could someone explain me why this example is correct?
This example from result of random Tests. I actually expected
But the last array couldn't pass test but
var sol...
pass it easy. Probably i just wrongThe only thing that cancels out is the "WEST, EAST" part, everything else should remain the same. You shouldn't change the order or directions.
.
Yea these edge cases of empty arrays came a little surprising. Not sure if I missed that in the description but it was a bit annoying. Still, thanks for the task!
When I "test" my code the fixed tests are passed. But if I "attempt" my code, the fixed tests fail but the random tests pass. Dafuq? Is there some sort of mistake in the tests here, because my code works perfectly fine.
What language?
Your code seems to pass now. Did you find your mistake?
I tried your code; I get:
Note there are more fixed tests when you "Attempt".
No. Look at the top of the page: 2719 people passed the C++ kata. Before posting issues look how many people passed the kata in your language. If there were errors somebody would have seen them before you... and you would avoid to make people waste their time:-) Reading this: "https://docs.codewars.com/training/troubleshooting could help you. Good luck!
Yes I found my error. It was a small one.
@g964 Just because people solved it in the same language it doesnt mean there are no issues. Maybe Iam the only one with that approack unlikely but no impossible. I really dont know why you are instantly taking about wasting time. Everybody does these mistakes even you.
Error: ['NORTH', 'EAST'] should equal ['EAST', 'NORTH']
and when i do a reverse it becomes
Error: ['EAST', 'NORTH'] should equal ['NORTH', 'EAST']
WTF
Not a kata issue, print the input. Why are you sorting the result?
I think this is the best kata from g964 that iv done. No math and if i have to compare to other katas easy to understand too.
This comment has been hidden.
No:
It's a problem, with your code, not a kata issue.
I got the following error:
Failed asserting that Array &0 ( 0 => 'EAST' 1 => 'NORTH' ) is identical to Array &0 ( 0 => 'NORTH' 1 => 'EAST' ).
When I have the same ouput for both cases?
That's not the same path.
This comment has been hidden.
You're confusing the result of one test with the log of the next one, read this: https://docs.codewars.com/training/troubleshooting#print-input the log appears above the test result, not below it.
Thanks for you help. I knew i was making a mistake somewhere. Thanks to you i was able to fix my code with a simple "sorted". i don't why i had this problem just for this array but hey it just work now.
I describe a recursive situation in this kata and in others kata: In Kata, when trying to submit the solution, it's executed other tests not mentioned in test class, unabling the developer to finish kata. And the log's provided from this "hiden unit tests" aren't enough. I suggeest to remove this hiddent tests, or mention them in tests class.
That's not a kata issue, print the input yourself: https://docs.codewars.com/training/troubleshooting/#print-input
Instructions say: "Not all paths can be made simpler. The path ["NORTH", "WEST", "SOUTH", "EAST"] is not reducible.
However, when I run my code I get the following result among others:
['EAST', 'EAST', 'NORTH', 'WEST'] should equal ['EAST', 'NORTH']
Like the example case in the instructions, 'EAST' and 'WEST' are separated by a different direction. Thus, the test results are contradicting the instructions for this kata.
Print the input: https://docs.codewars.com/training/troubleshooting#print-input
Didn't realize this was an option, thanks! And idk why I was thinking the test result was informing me of the input, slip of the mind I guess.
This comment has been hidden.
This particular case is stated in the description, at the end:
"Not all paths can be made simpler. ..."
The "reducibility" criterion for this kata is a "local" one: you are only allowed to cancel the opposing effects of move N and N+1, if they are opposite, rather than being able to cancel a larger series of moves (like the 4 moves N,S,E,W returning to start).
Or, in the more poetic language of the kata description, ^ this ^ is what the following sentence means:
"Going to one direction and coming back the opposite direction right away is a needless effort."
Aahhhhhh ok. Thank you
This comment has been hidden.
Do you have a function named
dirReduc
in your solution?Did you rename the function which was provided to you in initial solution setup?
Not a kata issue.
I may be stupid... but how those test should pass?
['SOUTH', 'WEST'] should equal ['EAST', 'SOUTH']
['NORTH', 'NORTH'] should equal ['NORTH', 'NORTH', 'EAST', 'EAST']
['WEST', 'WEST'] should equal ['NORTH', 'NORTH']
The first value is what your function returned, not the input value. The other is the expected value. Read this: https://docs.codewars.com/training/troubleshooting/
thank you Sir.
This comment has been hidden.
This comment has been hidden.
Hi,
Check again the last instruction of your if : are you always at the beginning of your array ?arr.remove(arr[a])
remove the first occurence ofarr[a]
and that's not necessarily what you want.And I think you should add the "Spoiler" flag to your comment.
Edit : my bad, that's not the problem. Edit2 : correct answer.
And it works like charm. Thank you.
dont forget to close ;-)
Update to Scala 3
Approved by som1
It is a pity that we never know who approves.
I thought it was possible for mods to check this?
Maybe but I don't know how:-)
It was me who approved the translation.
I usually tend to not leave much feedback when approving updates of frameworks etc. because it's nothing but a boring chore, but I usually resolve suggestions. Apparently, this time I forgot.
No problem but Cw should always says who approved kata(s). At least we would be able to know whom to address in case of problems.
This comment has been hidden.
Please let everyone cope with arrays and this kata on their own. That's how one learns and improves. I marked your message with a spoiler flag.
My bad akar
This comment has been hidden.
Yes, because this is a problem with your code:
Work through your loop and see what is happening for the input
["NORTH", "NORTH"]
-You start with
i=0
, you get to the end of your while loop and nothing happens (none of your 4 conditions are met) so you incrementi
andj
by+1
in theelse
block.Then you re-enter/repeat your while loop, this time with
i=1
-> this is where you get the error message because your code then tries to access the list elementarr[i+1]
which doesn't exist -- hence the helpful message "IndexError: list index out of range"I kinda missed it. Thank you bro
Hello everybody. When I try to attempt my code i get a few errors like: ['EAST', 'EAST', 'NORTH', 'WEST'] should equal ['EAST', 'NORTH']. I am new to codewars so unfortunatelly this doesn't give me much information. Can someone tell me how can interpret this errors? Like what should be the array argument which should result in ['EAST', 'NORTH'] so I can understand which mistakes am I making? Thank you in advance
Hi. You must read the log like this : "your_answer should equal the_correct_answer". See there how to print the input: https://docs.codewars.com/training/troubleshooting/#print-input
This comment has been hidden.
Not an issue, the kata specification for reduction is very clear, reduce opposing directions only if they are directly one after the other.
Besides, there isn't enough information here for you to make these kind of assumptions, since we don't know specifications like obstacles, distances, etc. for exmaple:
Okay, my bad.
This comment has been hidden.
You're attempt to remove the element at that specific
ith
index, but you're actually removing the first occurence of that element fromarr
, you should instead remove elements based on indexing.Really cool kata, i loved it!
Traceback (most recent call last): File "/workspace/default/tests.py", line 38, in test.assert_equals(dirReduc(a), ['NORTH', 'NORTH']) File "/workspace/default/solution.py", line 5, in dirReduc a.remove(arr[n]) ValueError: list.remove(x): x not in list having this issue showing passed and shows exit code:1
Your code is buggy and producing an error. It tells you exactly what the error is:
arr[n]
is not ina
. Insert print statements to track the values and pinpoint what is going wrong.This comment has been hidden.
Don't post solutions in Discourse, and use a spoiler flag as soon as you post code somewhere (I put the flag on for you this time).
there is such a thing as markdown formatting, particularly for code you enclose it in triple backticks: ``` your code ```
anyway, from what I managed to clean from that mess is that you're mutating the array while looping over it. don't do that. If you delete items, the arrays size changes, and so your
n
will quickly become invalid as it is now too large.Function names should be
snake_case
in Pythonthere is already an issue about that: here
This comment has been hidden.
Yes, you can see that in the example in the description.
["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"]
evaluates to["WEST"]
As you can see, there is a sequence in the example that goes"SOUTH", "EAST", "WEST", "NORTH"
And that sequence is meaningless.This comment has been hidden.
No, the path is different.
This comment has been hidden.
?
a
should output['NORTH','WEST']
have you modified the first test case in the sample tests?
there is a missing
'SOUTH'
in the third indexdraw the movement in a paper.. it basically move all the way and returned to the same position.. then the last movement was towards "West"..
OP solved it, closing
I wonder if I should use a LinkedList for this
not that I understand what a linked list is anyway, but I heard that they can keep track of nodes effectively x3
hmm no
this has nothing to do with linked lists. but either way there's no pre-existing linked list class, so you'll just have to create one yourself for this kata ;)
This comment has been hidden.
i dont understand this kata... it is need to elimnate oposite direction but in second test oposite direction stayed in arry? can someone explain just condition of test?
the opposite direction has to be right away
Tested the exact some code in my ide. This was the input (The same as one of the tests)
input ['SOUTH', 'NORTH', 'WEST'] output ["WEST"]
This is marked as a failed test. Why?
'SOUTH' & 'NORTH' are consecutive opposite directions, so they cancel each other out and only 'WEST' will remain
I tested my code in vsc with the exact same fixed tests that it is saying I am failing on but vsc is giving me the expected result. In short, My code works but the tests are saying that it isnt working. (I am using python)
"It works on my IDE" is NEVER a point to raise an issue.
If you wanna be taken seriously, you have to prove your point:
Aside of that, with close than 60,000 solutions, the chances you found a bug are close to 0.
You should begin there, I guess: https://docs.codewars.com/training/troubleshooting
"NORTH", "WEST", "SOUTH", "EAST": array lengths differed, expected.length=4 actual.length=0
Why is expected result.length = 4 ? Basically if you stay, you still get there, what's the point ?
This specific example is in the Notes section at bottom of the kata description (basically you need to only reduce "needless directions that occur side-by-side" as explained in the Task section of description):
"Not all paths can be made simpler. The path
["NORTH", "WEST", "SOUTH", "EAST"]
is not reducible. "NORTH" and "WEST", "WEST" and "SOUTH", "SOUTH" and "EAST" are not directly opposite of each other and can't become such. Hence the result path is itself :["NORTH", "WEST", "SOUTH", "EAST"]
."C solution attempt results in "Unexpected signal: 6", "double free or corruption (out)". All sample tests passed.
426 people passed the C kata so I am sure there are no problem in the C version.
@Greentea_cup
size
is not enoughThis comment has been hidden.
My code passes all the fixed test but keeps on failing random tests...
["EAST","WEST","NORTH","SOUTH","NORTH","NORTH","NORTH","WEST","EAST","SOUTH","NORTH"] : expected [ 'NORTH', 'NORTH' ] to deeply equal [ 'NORTH', 'NORTH', 'NORTH' ]
When you start eliminating opposite directions(which would be the first four and last four elements), you are left with 3 NORTHs, not just 2. It should be NORTH NORTH NORTH, and not NORTH NORTH. Why is it expecting to have one less NORTH?
Check your code.
C language: I don't have much experience in C, so I feel the code is badly written and I'm messing with the dynamic memory allocation.
Tried, and passed the 4 tests. But, when I attempt, I pass 3 tests and then get the error message "Test Crashed Caught unexpected signal: SIGSEGV (11). Invalid memory access."
Observation: the only dynamic memory that is not freed is the return varible, since they tell that the function result will be freed. All the other dynamic memory allocated are freed in each iteration.
Can anybody give me a hint on where I'm messing this up? In the mean time, I'll try to do a non-iterative version.
This comment has been hidden.
This comment has been hidden.
Thank you very much, that solved the problem.
Kata itself is somewhat intheresting, but chosen directions metaphore is very confusing. Because traveling the path doesn't matter to a guy using directions e.g. N-W-E-S is reduces to no directions. But optimizing path to a final destination is not the goal also: making a lap with N-W-S-E is somehow reasonable. Working with something abstract instead of directions would make more sence.
This comment has been hidden.
The tests are good. Please read the description again. This message is not useful:
["North"...]
, the output array is totally depending of the whole input array, not just the first element:["NORTH", "SOUTH", "EAST", "NORTH"] -> ["EAST", "NORTH"]
.Can someone explain the "Not all paths can be made simpler. The path ["NORTH", "WEST", "SOUTH", "EAST"] is not reducible. "? This isn't making any sense to me.
all the directions occur only once, and so it cant be reduced
['NORTH', 'SOUTH', 'WEST', 'NORTH'] can be reduced to ['WEST', 'NORTH'] since
north
andsouth
are cardinally opposite directionsThank you. I read again the description with more caution, it's now I understood that is only about consecutive directions.
This comment has been hidden.
After sending an attempt in nim, I get the following result:
Time: 4598ms Passed: 101 Failed: 0 Exit Code: 1
StdErr:
I am not sure how to proceed as all the tests pass & the warning do not come from the submission.
I remember you already got some problems with Nim (sorry for that!). Once again I modified the place of the testing function and fixed the warnings. Thanks for your post.
Hi! I could translate to portuguese
Description is always in English...
This comment has been hidden.
I don't think your removal method will work like you want to. If you have something like ["SOUTH", "WEST", "NORTH", "SOUTH"], I believe your code will remove the first "SOUTH", which is not what you want (correct me if I'm wrong). However, you could use those indexes for that job.
I tried ["SOUTH", "WEST", "NORTH", "SOUTH"] and you were right. It removes the item without taking into account the position. Thank you so much, that was helpful
I'm lost 😄
This comment has been hidden.
Your answer is wrong, not a kata issue.
The text says "it's important to save yourself some energy, otherwise you might die of thirst" so "the task is to give to the man a simplified version of the plan" and if the path leads to nowhrere It's "better stay to the same place". I didnt understand why the man should walking only to came back to the starting point.
COBOL translation.
Approved.
Was already approved. Have I to do it again with the new one?
Yes please, it fixes a little issue with edge case. From what I understood it's better to do new fork for enhancement once a kata has been already approved, that's how monadius likes to do (I think it's better for the case we have to fork the tests again, for example for an update).
Done.
This comment has been hidden.
JS: Node v14 should be used along with its appropiate assertion tools (Mocha + Chai). Refer to this and this
done
This comment has been hidden.
Read this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll
The only Node's version available right now for this kata is 8, that's why it doesn't work.
I really liked this kata. It took me a while and I had to get out of my comfort zone. I did it in Python.
Thanks!
Task that do not allow you to chose an O(n) algorithm because you have to keep directions in order. So you have to go for O(n^2), something that you would definitly avoid IRL!
Check Solutions, O(n) is possible.
This comment has been hidden.
This is a problem with your code, not a kata issue. And please add markdown tags to format your code when posting. See there: https://docs.codewars.com/training/troubleshooting/
eбyчий гaмбypгeр, я пoл дHя прoтpaхaлся, ниxeра не pабoтаeт
для гениев, вроде меня: while (**hello) вот эта xyйня бляTь, при заходе за пределы массива, не завершает цикл, а уходит в ошибку : SIGSEGV (11). Invalid memory access.
I don't understand. This website uses English. You may use a translator.
ofc, i am not writting it for you, my friend-gamburger. it is not actually translatable, so you have to learn russian to understand, sorry.
I understood that need save the sequence but i don't see it in intstructions. And "… a man was given directions to go from one point to another." but " Hence the result path is itself : ["NORTH", "WEST", "SOUTH", "EAST"]." Why man need walk around if he comes to the same point?
Because the man was given directions to go from one point to another. If he just stays still people will think he hasn't reached his destination.
The man is standing on a mountain. While walking N, W , S his latitude changes and by E he'll be entering a cave deep in the mountain for his next Quest.
I had an challenge - to solve it and put negative score to this task. And I did it!!! Terrible description...
I agree, the description is disgusting, I've read it 10 times and I don't understand what they want from us. It would be good for the author to give more understandable examples and descriptions.
Can anyone tell me what this means? i ran the test and it showed green then this appeared:
UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0xffffffffffffffe8 (pc 0x000000429c3b bp 0x000000000005 sp 0x7ffc4262c180 T1) ==1==The signal is caused by a READ memory access. ==1==WARNING: invalid path to external symbolizer! ==1==WARNING: Failed to use and restart external symbolizer! #0 0x429c3a (/workspace/test+0x429c3a) #1 0x4281a0 (/workspace/test+0x4281a0) #2 0x4268ce (/workspace/test+0x4268ce) #3 0x426423 (/workspace/test+0x426423) #4 0x425ffb (/workspace/test+0x425ffb) #5 0x42be05 (/workspace/test+0x42be05) #6 0x42571d (/workspace/test+0x42571d) #7 0x7fa7c2d06bf6 (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6) #8 0x4045d9 (/workspace/test+0x4045d9)
UndefinedBehaviorSanitizer can not provide additional info. ==1==ABORTING
Usually that means that you tried to access something that's out of bounds. Try printing things to console window, every step of the way.
You probably looped with checking for arr[i] and arr[i+1], this can go out of bounds and cause undefined behaviour. Try checking backwards.
totally buggy, order shouldnt matter and writing a different algorithm which solves the task is considered wrong.
No, order matters. You're trying solve a task that's not this one.
Not a kata issue anyway.
This comment has been hidden.
Your for loop is wrong somewhere. Maybe you should make more 7-8 kyu kata before.
ok!
This comment has been hidden.
I've added a special character to your
regex
at each segment and it worked! So, you must consider that test case (last 2 consecutive opposing directions of the array in terms of positioning) and modify theregex
This comment has been hidden.
Please use spoiler flag when posting code snippets.
I don't know if this is the only problem, but you remove one element at index i, then the remaining elements from i+1 are shifted left, and you remove i+1 th element, skipping the one you wanted to remove.
This comment has been hidden.
This comment has been hidden.
It's a great journey indeed when you don't read the description :>
This comment has been hidden.
Please only mark issue for kata issues.
arr[len(arr)]
is out of range since indexing starts at 0.Also, you can use markdown to format your code.
This comment has been hidden.
You're not necessarily going the same distance with every direction change. Imagine a network of mountain trails; the junctions between trails may not be equally spaced.
NORTH WEST SOUTH EAST
might represent, say, going 10 miles north to the next junction, 5 miles west, 5 miles south and 2 miles east.lol on your way we will suppose that: 'NORTH','SOUTH' may represent:say,going 10 miles north to the next junction,2miles south
This comment has been hidden.
If you ask this question, you did not understand the kata. Read the description carefully, you'll find the answer, it's very clear.
Yes, I know what you mean. The order matters in this kata.
What I was thinking about is that for example if you are moving on a flat surface(so like on earth when covering short distance), then the instructions: Go N->E->S can be simplified to simply Go E. I assume that since goint north is like going upwards, south is going downwards so they cancel out, but now how I understand is that this kata doesnt have to imitate real life situation therefore I shouldn't deep digger in that, just stick to the rules given.
The kata says this is the mountainous Wild West. Hence it can be assumed that such instructions can't be simplified as they may be navigating around obstacles
yes, fair point
I passed 3 tests but I get this error Traceback (most recent call last): File "tests.py", line 42, in test.assert_equals(dirReduc(a), []) File "/workspace/default/solution.py", line 3, in dirReduc if arr[i]=="SOUTH" and arr[i+1]=="NORTH": IndexError: list index out of range
The error message reveals that your code is trying to access an element at an index not within range of the indices for this object. This most likely occurs at
arr[i+1]
.This comment has been hidden.
Your code returned
['NORTH']
but it should've been['NORTH'; 'NORTH']
. What was the input case?Thanks, I just realized I misunderstood what it says. I thought it was saying that in case of "North" the output should be ["North", "North"]
Closing.
This comment has been hidden.
Correct, but this kata works with different rules. See description for this exact case and clarification.
I dont get the rules then lol. If you go NORTH, WEST, SOUTH AND EAST , I end up in the same point I started. Are the directions in a global coordinate or they are relative to the guy walking?
Please, improve task description. What should be the order of strings in returned array?
The same as it was, minus the reduced directions.
This comment has been hidden.
If the path is important, order matters.
This comment has been hidden.
I believe that's the case (also assign its size to pointer 'lg'). The author can confirm or deny this when online ;-) Are you passing sample tests?
Thank you, I finally finished this kata :) Yes, it is expected that the function will allocate memory for the result array. Perhaps the solution is not the most optimal, but the kata was interesting and made the beginner's brains work :D
This comment has been hidden.
Just glancing at your code, it looks to me that you remove opposite directions, no matter where they are in the array. That's not correct, because for this kata the rule is to only remove opposite directions if they are next to each other (adjacent).
This is why, for example: for ["NORTH", "WEST", "SOUTH", "EAST"]: the result is the same, and not [].
So it's just my inattention. It's something funny to feel that my mistake was not in the code but in the ability to read the terms)
Thanks for your reply because of I thought that 2-3 hours only on finding mistake were without effect.
Very enjoyable kata.
I used the same strategy I used in "Valid Braces" the only one solution I could think of.
Glad I remembered it.
Tried to solve it with c++, I have passed the tests but when I click on attempt I get the following error from the compiler: UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x004854524f4e (pc 0x7fbbc92634e1 bp 0x7ffd24eee160 sp 0x7ffd24eedbe8 T1) ==1==The signal is caused by a READ memory access.
From what I have read it can be because I have used a pointer that is actually Null. But my for-loop looks like: for (auto i = arr.begin(); i != arr.end() - 1; i++)
I don't think that the pointer will point to somewhere NULL. (?) or what might wrong with my code?
It's difficult to tell without seeing your code, but my guess would be that your iterator goes out of bounds at some place, ot gets invalidated by modifications of underlying container.
Thanks, I'll try:)
This comment has been hidden.
You're reducing directions that are not directly opposite of each other.
Closing.
ez breeze
Almost destroyed my soul but I solved it..... damn that was painful
AHA! Your soul has been tempered, tried, tested, and triumphed! You are more powerful now and will take the next challenge with no fear!!1!
this instruction, is just pointless. North West South East
is not reducible, because you will end in the same point you started in? What is the point, of walking in a circle, if you want the shortest possible path?
If you take N and come back S same way back then E and come back W same way, you'll finish at the same point. But if you go N=6, W=8, S=3, E=1 you'll end not in 0,0 (start point) but at 3,7. Imagine labirynth, where corridors aren't the same length.
But the same is with NSEW when you got N=6, S=3, E=1, W=8 you wont be on the same place either. I wouldn't compare this kata to anything concrete. It has got its own rules.
I agree. Instruction is stupid
Great one. Restrictions of the problem make for a good challenge.
This comment has been hidden.
I have explained (I hope) how it works, kinda puzzle bobble or candy crush.
Hi, thank you for replying. As I explained in my original post, i already understand how it works. My issue is that this doesn't seem to apply to the test case i detailed "NORTH", "WEST", "SOUTH", "EAST": array lengths differed, expected.length=4 actual.length=0
If you follow this path in your head or on a piece of paper, you will realize that you end up at the same spot as you were in the begining yet the test demands that the output should be of length 4 and not 0/null.
No, you would've solved it by now.
But that's not what the kata is asking for. You have to stick with what's asked here, and none of these directions are directly opposite of each other.
Then what is the point of the kata if the result is still not an optimum solution? In my opinion this is illogical
This comment has been hidden.
That being said, the test seem to randomly utilize both logics.
Can I please get an explanation on why this is happening?
Asking for an explanation is not an issue.
BTW: Before posting issues,
be sure you entirely read and understood the description
look at the top of the page: 4765 people passed the Java kata (out of a total of 47599). If there were errors in the tests someone would have already seen them before you.
Cheers.
Can't attach screenshot, but getting a fail with the following:
input: dirReduc(['NORTH', 'EAST', 'NORTH', 'SOUTH']) output: ['NORTH','EAST']
! ['NORTH', 'EAST', 'NORTH', 'SOUTH'] should equal ['NORTH', 'EAST']
Your code is wrong. Berore posting issues look at the top of the page: 15629 people passed the Python kata; when it is this high chances are your code is wrong: not a kata issue.
@monkey-bidness Please read this: https://docs.codewars.com/training/troubleshooting
This comment has been hidden.
It's a question, not an issue. 15606 people passed the Python kata so I am sure there is no problem in the tests. Issues are for problems in the kata itself, not for problems in your code.
Print the input!
Not sure what the issue is, but the solution input provides all of the solutions but isn't getting picked up for some reason.
C# tests are wrong: test(7): input=[SOUTH, EAST, SOUTH, SOUTH, EAST, NORTH, EAST, NORTH] Test Failed Expected is <System.String[8]>, actual is <System.String[4]>. But 4 is right! test(10): input=[NORTH, EAST, SOUTH, NORTH, SOUTH, SOUTH, SOUTH, NORTH, EAST, NORTH, NORTH, EAST, SOUTH, EAST, SOUTH] Test Failed Expected is <System.String[11]>, actual is <System.String[5]>. test(8): input=[EAST, NORTH, EAST, SOUTH, NORTH, NORTH, SOUTH, EAST, SOUTH, SOUTH] Expected is <System.String[6]>, actual is <System.String[4]>
Those error messages look good to me. Make sure you haven't misunderstood the task.
Sorry, no errors in the tests. C# kata passed by 3131 people. If something was wrong don't you think that somebody else would already have seeen it?-)
Please when posting an issue give the input, your output, the text message.
Ok, I guess I can't understand the task. As I understand it, the results should be as follows: [SOUTH, EAST, SOUTH, SOUTH, EAST, NORTH, EAST, NORTH]=>[EAST,SOUTH,EAST,EAST]. [NORTH, EAST, SOUTH, NORTH, SOUTH, SOUTH, SOUTH, NORTH, EAST, NORTH, NORTH, EAST, SOUTH, EAST, SOUTH]=>[EAST,EAST,EAST,EAST,SOUTH] [EAST, NORTH, EAST, SOUTH, NORTH, NORTH, SOUTH, EAST, SOUTH, SOUTH]=>[EAST,EAST,EAST,SOUTH] I missed "Write a function dirReduc which will take an array of strings and returns an array of strings with the needless directions removed (W<->E or S<->N side by side)." Sorry, "side by side" by google translator like: "Near", "in the same array". If there was such an example, I would understand the error right away
Nice Kata if u catch the concept it's pretty easy
Nice Kata, but i don't understand why a path like NORTH EAST SOUTH WEST is not reductible the Cowboy will go back to it's initial position. My first solution was to to return an empty array and make the guy stay at his initial position but the solution expect the entire path NORTH EAST SOUTH WEST and the cowbow should travel through direction to comeback to its initial position.
I got the exact same problem. It doesn't make sense.
This comment has been hidden.
This comment has been hidden.
That path is reductable. You chose a wrong example.
I have only one attempt failed: "random 10 directions: array lengths differed, expected.length=8 actual.length=4"
WHAT WAS the "random 10 directions"????
Print the input.
Sorry I do not understand you. Could you be more specific?
https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#print-input
Oh, thank you, I got it! I was really stupid. Thank you again!
This comment has been hidden.
Using python, I get this:
Test Results: Log ['WEST'] None should equal ['WEST'] Log ['NORTH', 'WEST', 'SOUTH', 'EAST'] Test Passed
First line, seems correct to me...
Your function is returning
None
, check why.Thanks. Fixed it. But I thought "Log" was the printout from my function.
What your function prints (it can be the input, the output or some other value in between) and what it returns are two different things, check this out: https://docs.codewars.com/training/troubleshooting#expected-the-same
This comment has been hidden.
Potentially helpful links:
Yeah! Many thanks! I changed all iterators to size_t and it started to work fine.
How to see the input in the test to understand where the error comes from? At the moment I see only an error, but I don’t know what data was received. I only see the input in the first tests.
Print the input.
Failed asserting that two arrays are equal. Expected: Array ( 0 => 'NORTH' 1 => 'WEST' 2 => 'SOUTH' 3 => 'EAST' ) Actual : Array ( ) выдает ошибку, хотя по массиву видно что он возвращается в ноль и правильный ответ пустой массив
Very poor problem statement. Not all reasonable assumptions have been accounted for.
This comment has been hidden.
The
dupes
list for 4th test case is[0, 1, 2, 3, 5, 6, 6, 7, 8, 9]
. So, when you delete the element at6th
index from thepost
list,post
only has 6 elements (range from index 0 to 5), hence the error.I'm running into a weird issue. When running the attempt, I get 1 passed, 0 failed. However it exits after one test and gives error 'pop index out of range' on the input ['NORTH', 'NORTH']. The weird thing is when I run the exact same code with the inputs ['NORTH', 'NORTH'] in my IDE, it runs fine without error and gives an output of ['NORTH', 'NORTH'] as it should.
Why is this happening?
Not sure if it's ok to post code here. I can post it upon request.
Hi @Waleed-Alfaris, this kata has been under heavy scrutiny for some time, and is fully vetted in Python with over 15K solves. The
issue
tag is for problems with the kata where you can show evidence of some error. If you are unsure about why your code does not work, you can post as aquestion
instead. If you wish, you may post your code with proper markdown and a spoiler tag, someone can check it for you.This comment has been hidden.
Please read the description again. There is this exact case explained. (check the notes section)
This comment has been hidden.
Thinking that a kata "doesn't make any sense" is not a kata issue. It is your opinion and I respect it but please note at the top of the page that 45,701 passed the kata.
I'm agree with you. I don't understand this test case.
This case is explained in the description.
Explained doesn't mean it isn't wrong. I just ridiculous.
Hi. I find answer on my question.
This comment has been hidden.
"WEST, WEST" because they aren't opposites. If you go west 2 times then you don't come back to your starting location.
is 5kyu appropriate or should it be a 6kyu?
Too late anyway
yea xd anyways nice kata!
Elixir:
Solution setup has module definition commented out. There is no good reason for this, is there?
I don't know when that happened. Nobody noticed it until now. Fixed and thanks!
Errors for my python solution seem to conflict each other, such as:
['EAST', 'NORTH', 'WEST'] should equal ['WEST', 'NORTH', 'EAST']
(here 'EAST' and 'WEST' have not cancelled each other but the list is inverted)
['EAST', 'NORTH', 'NORTH', 'WEST'] should equal ['NORTH', 'NORTH']
(here 'EAST' and 'WEST' DO cancel each other but are on opposite ends of the list)
I don't see how the desired output is in accordance with the given directions for the kata.
It's impossible to pinpoint the problem given only the test output. What we need, in order to check validity, is also the input. Could you try again and this time show both input & output of the failed tests? That would help! :)
This comment has been hidden.
^ That
simply insert
at the beginning of your function to inspect the input. Follow along logically, step by step, what your code is doing. If you need to, insert print statements along the way to display intermediary values. Finally, read the docs, there might be some useful information there. I promise, the tests are correct for this kata. Any issue stems from your solution :) Also: to insert a code block in your reply, use markdown syntax: ``` your code ```. This preserves formatting and makes code easier to understand.
I'll give it another shot, thanks for your help!
I make a cartesian plane with x and y using a pair, west < x > east and south < y > north. So I make a for across a vector increasing or decreasing the direction . the final result is a value [x,y] , this is a final point. make a regression step by step i have the better way. I passed in the first test , but the other results are confuse.
Need save a path in initial order
This comment has been hidden.
Tried to solve with c++, I have passed the tests but when I click on attempt I get the following error from the compiler: UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x004854524f4e (pc 0x7fbbc92634e1 bp 0x7ffd24eee160 sp 0x7ffd24eedbe8 T1) ==1==The signal is caused by a READ memory access.
From what I have read it can be because I have used a pointer that is actually Null (not sure because I never used clang) the point is that in Visual Studio the program compiles and works correctly, so I dunno :(
Please read this: https://docs.codewars.com/training/troubleshooting/
Your solution crashing is not a kata issue. Your solution contains some out-of-bounds read, but it's difficult to tell exactly without seeing your code. Most probably it does not crash in your local VS just by luck
Yeah thats what I thought too, I'm gonna try again thanks to both for the reply.
Hello, have you solved the problem? I met exactly the same problem yesterday, and I still don't know what's wrong with my code lol
Hello, have not found a solution so I just rewrote the code with a different approach :_) . I know that this does not help at all but I was just overcomplicating the problem and going out of bound of the vector. Still don't understand why it was working in VS.
This comment has been hidden.
Direction entry should be in capital letter and enclosed in quotes :) Just by looking at your entry I see these reason for test failure.
Haskell? There are no error in the tests; you can notice that 736 people passed the Haskell kata.
@jyotiska: if you know Haskell look at the template solution:
data Direction = North | East | West | South deriving (Eq)
.Sorry didn't read the last part
a = ["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"] test.assert_equals(dirReduc(a), ['WEST']) My code is giving output as ['WEST'] yet the validation is failing. What is going wrong ? Second test is passed.
I tried your solution; For the 1st test I get:
It means you should have returned "['WEST']" and you returned "['NORTH', 'SOUTH', 'SOUTH', 'EAST', 'WEST', 'NORTH', 'WEST']". You pass the second test because the ouput is the same as the input and your code does nothing... You have to entirely rethink your algorithm, sorry. Cheers.
Apologies , i had missed on declaration But now even after all test case passed, i am getting the following error
"maximum recursion depth exceeded in comparison"
unable to submit because of this
Your recursive solution has gone into a loop and is calling itself indefinitely so the tests crashed. You have not passed all the tests.
Your solution still has an error. Print the input and run through the test case that causes the error manually to see what the issue is.
I passed the first test but then I got errors .Thought the annihilation of the given directions was done identifying the directions from left to right as the example.
This comment has been hidden.
Sorry, not an issue, rather a question. I don't see any sort in your solution. Note at the top of the page that 14,700 people passed the JS kata.
This comment has been hidden.
define "here"? (language? version?)
This comment has been hidden.