6 kyu
Swap Case Using N
1,153 of 1,875mjjbycicle
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.
Very interesting kata.
Good kata, but there is a problem with Swift unit tests and example
func swap(_ s: String, n: Int) -> String { // _ is missed before n
XCTAssertEqual(swap("the quick broWn fox leapt over the fence", 9), "The QUicK BrowN foX LeaPT ovER thE FenCE")
duplicate of this issue
Description is inconsistent.
Each bit in n will specify whether or not to swap the case
versusbecause 11 is 1011 in binary, so the 1st, 3rd, 4th, 5th, 7th, 8th and 9th alphabetical characters have to be swapped
. You really need to describe this more carefully.The description states:
And:
What is inconsistent here?
Because of the each bit in n part;
11
is not represented as1011
for each bit in n, but rather as0..0001011
(depending on size of int).You need to replace "func swap(_ s: String, n: Int) -> String" with "func swap(_ s: String, _ n: Int) -> String". Then the error "type of expression is ambiguous without more context" will disappear
duplicate of this issue
C translation (author inactive)
Thanks :)
This comment has been hidden.
This comment has been hidden.
On Swift 5.3, no matter what the solution is, compiler gives out "error: type of expression is ambiguous without more context" for every single test case.
I got that too, but then worked the kata in xcode playgrounds, copied the entire function back over to the kata, and it worked as it should do.
fixed
Ruby 3.0 should be enabled, read this to learn how to do it
Please organize the structure of test fixture as following (although it has been mentioned in the attached link, I'm repeated here again)
fixed
This comment has been hidden.
Something weird ... my program passes the 7 test cases but fails all the random test cases. Furthermore, a binary representation of an integer should always start with 1 which means that the first character should always be swapped but in the random test cases there are many characters at the beginning of the string that are not swapped - don't know why ...
Same problem with me I dont know what to do
Same here - after attempting my first try from yesterday, just to see and analyse why those randos fail, it suddenly works! OoooK ... ? Maybe you guys check again - seems the author worked it out ...
The same thing happens with me, it does not make sense. In the end it worked even though I did not change the code
My problem when I got this was I forgot to check for characters other than spaces. The random tests have lots of punctuation in them.
Haskell translation
approved by someone
( JS, possibly others )
No example tests.
Fixed ( for JS )
( Other languages don't have this problem.)
C++ translation
Approved by someone
Swift version. I get the following error no matter what I am returning for all test cases:
Happens even when returning a simple "".
there are mistake in this row func swap(_ s: String,_ n: Int) -> String {
Thanks, I missed that one!
Ruby translation kumited, including updated description -- please check and approve
approved by someone
Swift translation: https://www.codewars.com/kumite/5f4ab229f0cc51002df9e8dc
Fun Kata, no issues.
Nice piece of work, author!
Cool kata!
What's going on here? is n 11 or 9?
Sorry I messed up while making some changes. It should be fixed now.
Sorry I messed up while making some changes. It should be fixed now.
Sure - still don't get what to do though. bin(11) = 1011
So swap all the characters with a '1' underneath them?
Yep.
Yep.
Not sure why my replies appear twice, but I only clicked once. Do you guys see that?
Not sure why my replies appear twice, but I only clicked once. Do you guys see that?
But my diagram implies the swapping of the first, third, fourth, fifth, seventh, eighth, and ninth alphabetic characters (counting form 1)? Is the example still using n = 9?
Yeah but it's only happend to me once before... should go away if you restart your browser.
Thanks! I'll try that.
Thanks! I'll try that.
Thanks! I'll try that.
thrice?
thrice?
okay looks fine now (maybe mention that indexing starts from 1?)
It's not obvious from the description that the bits should be in the reversed order, how about an asymmetric example instead of
1001
?Perhaps you don't want to say binary integers here.
Why not just "integer"?
Just revised. Thanks!
Accidentally pressed twice.
Description should mention that we are supposed to skip the checking of bit when a non-alphabetic character is encountered.
Thanks for the suggestion! I just revised the description.
As this is beginner-level kata, you should add a good example which exposes some edges cases, and provide its full solution.
Like:
ifeufh!!! ewuhe ?oieffe
the description mentions this now
New test framework should be used.
I've changed it to use the new test framework. Can you take another look?
Sample tests are still using the old framework, and imports for enabling Python 3.8 explicitly are missing.
I've fixed the sample tests. Can you tell me where I can find resources on the imports for python 3.8? I'm not very sure what they are.
I've fixed the sample tests. Can you tell me where I can find resources on the imports for python 3.8? I'm not very sure what they are.
The template for writing tests clearly specifies this...
Can you tell me what its supposed to do? I can't find it on other test cases or in the codewars wiki.
Can you tell me what its supposed to do? I can't find it on other test cases or in the codewars wiki.
I added the imports. They are supposed to be only for python 3.8, right? Could you review again? Thanks.
Sample tests still don't have them.
Sorry I keep on forgetting that there are sample tests. I fixed it. Thanks for catching lots of mistakes!
Sorry I keep on forgetting that there are sample tests. I fixed it. Thanks for catching lots of mistakes!
Input generation is very slow, and there's no point in testing thousands-characters-long strings.
I've made the tests faster and simpler. Can you take another look? Thank you very much!
Good enough.