6 kyu
Mexican Wave
1,805 of 72,090adrian.eyre
Loading description...
Arrays
Strings
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.
Great job! I was stumped for the longest time.
This comment has been hidden.
This comment has been hidden.
C# works good. Nice question..
This comment has been hidden.
JavaScript. I use VSCode to solve and then copy-paste here. For some reason result is different in this kata. VSCode returns correct answers and test cases here are wrong. Why is that?
I cannot be absolutely sure, but it's quite unlikely that your code returns a different result in VSCode and here (though, there may be minor differences of implementations, but this doesn't happen often). Your code works fine on several tests, but fails on some others, you should focus on it and try to find where your code is wrong:
See there for a general help: https://docs.codewars.com/training/troubleshooting
I got that extra ' gap ' here without any capitalization. I'll try again tomorrow but I ran all the test cases in VSCode and they return correct result (definitely no extra words in array)
The test cases return [ 'Gap', 'gAp', 'gaP' ] [ 'Hello', 'hEllo', 'heLlo', 'helLo', 'hellO' ] [ 'Two worlds', 'tWo worlds', 'twO worlds', 'two Worlds', 'two wOrlds', 'two woRlds', 'two worLds', 'two worlDs', 'two worldS' ]
I really don't see where the mistake is. Scratching head
This comment has been hidden.
Same with me
Beautiful
This comment has been hidden.
it seems you are returning an array while you should return a string. I cannot tell much more, I have not solved the kata in PHP.
Love this kata :)
This comment has been hidden.
C#: Function name should use
PascalCase
(Please refer to implementation of backward compatibility here )target
should bechar *const *
in CIn python version mistake in test_case6: given same incoming string (" gap ") as in test_case5, but your test waiting for difffernt return (["A b ", "a B "])!!!
No, you're wrong, the input is not the same.
Tests are fine.
Broken kata, sigsev on C though works in onlinegdb and my pc. Dunno how "target[i][wave_ch] = ch-32;" can cause sigsev with good indexies
Its because you are passing to target[i] pointer to const value and try to modify. Assign "some" memory on heap, copy context from y to this blocks and then do operations on this
the issue is in your code, you are not handling spaces correctly. the
""Two words"
test case makes your code crash because you accesstarget
at a wrong indexThis comment has been hidden.
Doing it in C, honestly don't know what is the difference between:
"Hello","hEllo", "heLlo","helLo", "hellO"
and"Hello", "hEllo", "heLlo:", "helLo", "hellO"
. The test result also isn't very helpfull...:The expression (strncmp(rs[i][j], target[j], r)) == (0) is false.
See the 3rd hello, yours has a : at the end. Not a kata issue.
I tried to improve assertion messages.
@Chrono79, that's just my missclick when writing the issue :/ it isn't there.
@MFoxx, read troubleshooting docs, post your code so we can help you.
Actually I'm just dumb, it works now. Sorry everyone...
Working in Ruby and stuck because of the handling of variables. All elements of string in array point to same object, so modifying it causes all the elements to change. Hint needed. How do get multiple objects that all are the same word?
This comment has been hidden.
"expected [ 'Hello', 'hEllo', 'heLlo', 'heLlo', 'hellO' ] to deeply equal [ 'Hello', 'hEllo', 'heLlo', 'helLo', 'hellO' ] " not sure how my answer is incorrect; can anyone spot the difference?
heLlo not equal helLo
Your answer is wrong, not a kata issue.
silly me, very tired
I'm having the same problem.
This comment has been hidden.
This comment has been hidden.
not a fan of the description. just give the task and get on with it. not here for a story time. maybe just me
Lua translation
Thank you
The "Am I safe to drive?" kata link in the description links to this same kata (Mexican wave), instead of this other kata.
This should be the url in that link: https://www.codewars.com/kata/58ce88427e6c3f41c2000087
Updated
D translation
This comment has been hidden.
Hi. This is a problem with the test framework, it considers your answer is incorrect in case the result is an empty slice depending on how you initialized it.
This requires manual fixing. I have just published a new version of the tests that should handle it properly (you may need to click
reset
at the bottom of the trainer page to get the new version; save your code locally if needed because it will be lost).The explanation is, you may know it already, there are two valid methods to initialize an empty slice in Go:
The first creates a slice of size 0, the second is
nil
(which is also of size 0..., Go subtleties) until you fill it with something. If the expected result is empty, the tests will consider your answer incorrect if you have not initialized your answer with the same method as the tests.If you face another similar issue on some kata, please raise an issue so that someone can fix the tests, and temporarily you can try to switch to one or another method to initialize your slice to pass the kata.
Interesting kata with diligent decor
I'm getting this.
Should return: 'Two words,tWo words,twO words,two Words,two wOrds,two woRds,two worDs,two wordS' - Expected: ['Two words', 'tWo words', 'twO words', 'two Words', 'two wOrds', 'two woRds', 'two worDs', 'two wordS'], instead got: ['Two words', 'tWo words', 'twO words', , 'two Words', 'two wOrds', 'two woRds', 'two worDs', 'two wordS']
Should return: ' Gap , gAp , gaP ' - Expected: [' Gap ', ' gAp ', ' gaP '], instead got: [, ' Gap ', ' gAp ', ' gaP ']
That's a problem with your code, not a kata issue.
Its bullshit but problem is - we can`t capitalize " ", just add if statement to skip space character.
Ok so this is what I get:
Should return: '[ Gap , gAp , gaP ]' ['Gap', 'gAp', 'gaP'] should equal [' Gap ', ' gAp ', ' gaP ']
I don't quite understand what is wrong. I have made the answer both for being iqual as ['(space)Gap(spave)', '(space)gAp(space)', '(space)gaP(space)'] but still get it wrong
Read this: https://docs.codewars.com/training/troubleshooting
This comment has been hidden.
This comment has been hidden.
mine's not setup like yours, and im not sure if you'll see this, but I had it check if string[repition] != ' ': list.append(changed) so it only appends the list if the character at the number of repitions is not a space
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
the indexing doesn't work the way you want it to, since the behaviour of
result = [list(people)] * len(people)
is kinda wierd. your input makes five references to the same list. this can better clear your doubtsThanks, I've learned more about duplicate objects that point to the same thing. I'll be more aware of it now.
This comment has been hidden.
Your code returns the result after the first iteration of
i
in thewhile
loop has been executed.You will get the following message:
indicating that your result is
['Two words']
while the expected (correct) one is['Two words', 'tWo words', 'twO words', 'two Words', 'two wOrds', 'two woRds', 'two worDs', 'two wordS']
COBOL translation.
Thank you 🙂
Could you approve this fork with a minor fix? (problem with a size variable in the unlikely but possible case where the output would have a size of 100) https://www.codewars.com/kumite/61e1fdcb748f97000f701a32?sel=61eef6d90d874400172067a3
Thanks for the fix
This Kata is bothering me. Without changing my code it gives me different answers regarding the number of tests failed and solved
The tests are random
the wordings a bit off... in a mexican wave you can not just skip an empty seat. otherwise the wave will get out of sync when you have multiple rows...
This comment has been hidden.
It worked for me, what's the problem you see? Please read this: https://docs.codewars.com/training/troubleshooting
The problem was in the uppercased spaces, may be. The code behaved strangely without a line about spaces.
First time I've heard of this.
Please do not post any solutions in the Discourse. I marked your question a spoiler.
Dart Version returns:
Failed to load "test/solution_test.dart": type 'String' is not a subtype of type 'bool'
Not a kata issue, that's a problem with your code, simply returning
["A b ", "a B "]
doesn't show that error.thanks for the fast answer!
nice kata!
This comment has been hidden.
Look at the sample test with
"two words"
as input.Im in python, I'm gettin weird errors, Should return: '[ Gap , gAp , gaP ]' ['Gap', 'gAp', 'gaP'] should equal [' Gap ', ' gAp ', ' gaP '] As I understand I made it right, such a shame I cannot get the points UnU
No, you didn't make it right. It's
['Gap', 'gAp', 'gaP'] should equal [' Gap ', ' gAp ', ' gaP ']
so you returned the strings without those spaces.Still does not work for me with spaces
[Edit] I was wrong, it should include the spaces, it was just that I made the algorithm wrong at the beggining
well made kata, thank you creator!
This comment has been hidden.
This comment has been hidden.
Hi SlideSolo. I'm afraid I didn't create the Go translation and wouldn't know where to start. This does not look like an issue however. it is because you are returning the wrong result.
This comment has been hidden.
This comment has been hidden.
It's impossible to help you if we don't know which language you're using, and how you're using replace().
I am facing the same issue. And definitely Maskell is talking about JavaScript. Can you tell me how to replace a character according to index.
This comment has been hidden.
C++ version generates warnings.
Fixed
Thank you Voile
Most test work but sometimes about every 70th I get a SIGSEVS(11)-error. Any ideas what could cause those?
Same here. My program worked well on my terminal and there was no errors.
The C code works fine, you just have to correctly assign the data.
When i do it on the console it all works, i get this output: -> [' Gap ', ' gAp ', ' gaP '] but when i test it on codewars i get the wrong output :'( :'( :'( :'( It says : Should return: ' Gap , gAp , gaP ' - Expected: [' Gap ', ' gAp ', ' gaP '], instead got: [' Gap ', ' gAp ', ' gaP ', ' gap '] Anyone else that me got the same issue? If so what did you do to get it done?
It is the only issue i've got with this really cool and funny Kata
I think you're not skipping the trailing white space.
That was fun! I really wanted to do it with regex and array functions only, no slicing and no looping. I got it to work eventually...
What, shall we do a Mexican wave around the Earth?
c# template gives error:
src/Solution.cs(6,16): error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?)
I had to add:
using System.Collections.Generic;
Thanks for letting me know. I've updated the inital code to include this library.
This comment has been hidden.
This comment has been hidden.
The code for string replacement is wrong because you intended to replace all substrings with positioning beyond
counter
whilst the correct way is to replace the specified character with respective position.This comment has been hidden.
I think it maybe
string_array[counter + 1].upcase!
because if you are at the last index of the string it maybe out of bounds. Although Ruby may double back on itself. It'll be worth looking into it either way :-)Thanks so much for the help. Got there in the end and the code is a bit clunky, but I learned about the safe navigation operator which is real handy.
The C test code gives compilation warnings.
Fixed by using your solution, hope you don't mind.
All that was missing was a few includes... but I don't mind if you attribute the code to me.
Any chance I can get the solution for that?
Hi @axelrows, sorry it doesn't work like that :-)
You can either solve the kata yourself then look at other peoples solutions or you can forfeit the kata by clicking "unlock solutions" which will mean you wont gain the points :-)
Another fine kata from adrian.eyre! I especially love ones that reward solid error check coding!
Thank you. Glad you enjoyed
great katta, I had to dig a little bit in stack overflow
This comment has been hidden.
Try not removing them in your error checking, instead skipping them.
This comment has been hidden.
tmp
is missing a byte for the nul terminatori
for every character iny
, and you also usei
to indextarget
. So if there are non-letter characters iny
, you will write out-of-bounds oftarget
.Straightforward and otherwise-excellent Kata, BUT description is completely illegible if screen is set to Light mode. In Dark Mode it looks fine. Can this be fixed?
Updated
@adrian.eyre why it's like that in the first place? Anyone can easily remove the CSS and HTML and make it pure markdown, what's the problem?
Rust translation
Thank you for the translation :-)
You're welcome! It was fun :-)
Have a great day!
The C++ compilation of the test case gives 2 warnings that can be very easily solved if somebody has edit access to the test (both of the variety where int is compared to size_type)
This comment has been hidden.
Are you sure. The test for " gap " should have the result [" Gap ", " gAp ", " gaP "] which it does for the sample and final tests. Is your code taking blank spaces into consideration?
There has been 167 successful attempts in Haskell with no issues. As explained above the output for that test should be [" Gap ", " gAp ", " gaP "]. Resolving issue.
One of the coolest katas I've ever done! Great one!
This comment has been hidden.
Your code does not obey to the following:
If the character in the string is whitespace then pass over it as if it was an empty seat
This comment has been hidden.
Is there any issue with the last two tests? Because my code works on playgrounds but not here (using swift)
it tells me "("[" gap ", " Gap ", " gAp ", " gaP ", " gap "]") is not equal to ("[" Gap ", " gAp ", " gaP "]") -"
This is the result that I get on playgrounds : [" gap ", " Gap ", " gAp ", " gaP ", " gap "] which is the expected result. It seems like it's testing for "gap" and "twowords" without the actual spaces.
the result for " gap " should be
[" Gap ", " gAp ", " gaP "]
Oh right thanks! I forgot to skip the whitespaces
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Sorry you're right, I've update this
Thanks!
This comment has been hidden.
The input is
const
. I guess it's already fixed...The input is instantiated as const, but the input parameter is not, so if you derefernce the pointer and increment it within the function (which the compiler will allow because of scoping), you segfault because it's modifying immutable stack data I'm not sure how to edit kata's to submit bugfixes
Updated.
This comment has been hidden.
Op solved it, closing
This comment has been hidden.
This comment has been hidden.
The template in this challenge (JS) should accept paramaters, like so:
Added
Nicee!
Swift translation added.
Thank you
Groovy, Elixir, Julia, and Kotlin translations.
As always, thank you for your translations.
You might update the tables at the bottom of your katas to be updated with the latest languages ;-)
Currently having an issue with submitting this kata in javascript, the the random tests seem to be testing the previous parameter string and then the current one?
No, the tests are ok:
Maybe you're confusing where the log appears, it appears above the test result.
This comment has been hidden.
This comment has been hidden.
Dart got glitched, here: https://www.codewars.com/kumite/5d545f3d7e60090d07fcbd35?sel=5d54ddc27d018e00266e280e
Could you apply this suggestion?
Done. When I created this suggestion I didn't have 10k honor.
Racket translation
Hi @metron6 thank you so much for this translation. I've never touched Racket so please could you keep an eye on any issues with this translation over the next few weeks please.
Sure.
Go translation and i love your kata 😊
Thank you and thank you for the translation :-)
I have made the fork version of my Go translation, so please approve it.
😃
Done :-)
Currently having an issue with submitting this kata in golang the test tel me its nil but its not nil
Could you tell me what test you were facing the problem?
Reason translation: https://www.codewars.com/kumite/5c8e616689a4a100164a3cc4?sel=5c8e616689a4a100164a3cc4
Thank you for the translation. I've had no experience in this language so please could you fix any bugs that may arise.
Of course, if it happend please send me some notification ore message to see it.
Clojure Translation
Here's a clojure translation :)
First Clojure translation, thank you :-)
I have little knowledge of Clojure so if there are any errors that are noticed in the first few days please could you fix them.
Definitely. I'll keep an eye out for any issues.
This comment has been hidden.
I've been playing around with this and I'm not sure why it is timing out. When I timed this implementation and put it against mine, it was about twice as slow for large strings (~3000 characters) but almost identical for small strings. But the weird thing is, even though it was twice as slow, I could only get it to pass around 10 random tests before timing out while mine could pass all 100 tests.
However, I did find an error in how large the strings were for the random tests. The other languages have random strings where the length is between 0 and 100 characters. The clojure tests were doing between 0 and 3000 characters.
Here's the fix for that bug and hopefully that will make your implementation pass. https://www.codewars.com/kumite/5c89cc3ead83841ec16a0e1d?sel=5c991d09d74b05250a1129d2
Approved the update. Thank you so much for looking into this and sorting :-)
Haskell : https://www.codewars.com/kumite/5bfbfee81fa0e347a1000035?sel=5bfbfee81fa0e347a1000035
Thank you for the translation.
The kata is nice, but It would be great if there is performance tests for this Kata. (actualy for c#)
A very nice visually enjoyable kata. Odd thing with whitespace behaviour in Ruby, I'll look for a more elegant way to handle it. The photo suggests an Arsenal fan authored this one, am I right?
Thank you :-) no not an Arsenal fan, Ive never really been into football just the first image I found :-)
Cool, well I'm saying this anyway "Did you see that ludicrous display last night? What was Wenger thinking, sending Walcott on that early?" :) Back on topic, it was the special case for first char in the string that was odd rather than whitespace, need to review. Adrian, could I possibly ask you about Makers Academy by direct message, not sure if dm is possible on this site? I have applied to do the course.
If you sign up for Codewars Gitter (https://gitter.im/Codewars/codewars.com) you can DM me on there :-) I'm always happy to help :-)
when I use toUpperCase and toLocalUpperCase function,why do they have no effect ?
Are you sure you're using them correctly?
I know this is 7 months ago but - if you're trying to change characters in a string, remember strings are immutable. Meaning you need to reinitialise it to have the edits take affect. I made the same mistake.
C++ Translation
Made you another :) I also added the cpp example in description.
Approved, thank you for the translation :-)
This comment has been hidden.
Hi @hjacobs3, I'm affraid I don't know enough Java to help. It maybe a good idea if you post you help request on the CodeWars Gitter (https://gitter.im), there is a channel for kata help on there :-)
One error is in Java you can't declare a dynamic array, you have to set its size beforehand (or at least that's what I've being told). Another thing you do wrong is only uppercasing so your code will end with all capital letters. You also loose spaces, overwriting str. There are more errors but with that you have something to work.
thanks a lot, seems that i don`t deseve 6Kyu.
Java has dynamic arrays called ArrayList. But your solution doesn't need them, just think about what Chrono79 said. It is possible to know its size beforehand.
how to delete all the spaces in java? i have tried commands ( like replaceAll(" ","");
Strings in Java are immutable, but if you reassign them, your command should do what you want. str = str.replaceAll(" ",""); If you want to remove all non-visible characters (e.g. tab, \n), go with: str = str.replaceAll("\s+","")
I would rather place an if statement in your for loop to only edit the characters which are alphabetical. do something like if(Character.isAlphabetical(string.getChar(i))) { }. This means the for loop will not do anything with the blank spaces so long as you're adding to the array in the if statement.
Java translation added! :)
Approved, thank you for the translation :-)
This comment has been hidden.
Nice catch. When reporting things like this, please mark your post as having spoiler content.
Thanks fot letting me know, now sorted :-)
motion to change to 7kyu
Only admins can do this now (-_-), but they will not. You can stop writing these comments.
Oh, that's dissapointing. I'll stop then making suggestions like this in the future.
By the way, do you think this https://www.codewars.com/kata/months-weeks-days-hours-and-minutes or this https://www.codewars.com/kata/tv-remote are 7kyu problems? Because if they are then i'd still group this task with them in same category, it is by no means more difficult than them.
Yeah, they removed this PU skill because it's too imbalanced ;)
I'm sorry, I think you had seen my comment before I edited it (I looked at the kata name but not the description, and thought that this was a different, harder and more interesting task). Yes, this one is easier than those 2 you pointed out.
Hi @Talrendis
Ranking isn’t necessarily on how hard the kata is but more on the language features needed to complete the kata… Ranking
When this kata was in beta the average rank was 6KU and the average ranking from Power Users was 6KYU that’s why the moderate of the kata (myjinxin2015) deemed it to be 6KYU.
If you would like to discuss this then I would chat about it in the Codewars Gitter channel :-), hope this helps :-)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I will look into this asap
This was a lot of fun to get my head around. My solution was absolute franken-code so it was good to see how much more eloquently it was solved by other users!
Good luck with Makers, you'll really enjoy it :-)
Simple kata but cool one!We need more katas like this,or i need :D.
PHP Translation
Thank you so much for the translation :-)
Crystal translation kumited :)
Thank you so much for the translation :-)
Fun kata!