6 kyu
Array Exchange
183 of 1,324hafizio
Loading description...
Arrays
Algorithms
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.
tricky, but not very enjoyable
Nice!
That was a tricky one in the first place. Had to come to the comment section to get the hint. I really enjoyed this one!
(c-version)
there is a typo in the provided test: The output message labels both expected strings as "S2" - should be labeled as "S1" and "S2".
what is this error: expected [ '7', '6', '5', '4', '3', '2', '1' ] to deeply equal [ 'c', 'b', 'a' ] my code wotks in browser console though...
You're not doing it in-place.
Instructions are insufficient and tests don't provide any feedback information.
what should be return from function
nothing, obviously.
This is a very tricky kata. You could have blame the author with such tricky problem, but just do what your mind says then viola it will work! then you will realize the logic the sensei wants you to know.
clue: the function is void, the length is different and the sensei is clever.
I dont understand , this is my output on my computer:
s1:c b a s2:7 6 5 4 3 2 1
but tests show:
[Actual] S1: [1234567] S2: [abc] [Expected] S2: [cba] S2: [7654321] [Input] S1: [1234567] S2: [abc]
please explain what happens ?
i dont understand what you need me to do after exchanging the values what should i return with
You need to modify the contents of existing arrays a and b inside the function, and not assign references to new arrays by these variables (parameters).
Their is some problem with the test? for example I get this message: [Actual] S1: [5dqlcb25nx31fk7e9399u1316x] S2: [0t85qx] [Expected] S1: [5dqlcb25n] S2: [0t85qx] [Input] S1: [xq58t0] S2: [n52bclqd5]
it seems that expected and actual are very different in len. and the test itself it seem to me wrong.
Not a kata problem. In fact, I see no problem at all.
Please amplify.
( JS, possibly others )
The example tests shows that the arrays are not necessarily of equal length. This should be in the description.
JS translation
For
C
is there some guaranee that the passed arrays are allocate big enough to hold each other?e.g. If strlen(s1) is 3 and strlen(s2) is 7, is it really OK to write 7 chars back to s1?
Seems a dangeraous thing to do, and description is unclear on this point.
Maybe I'm not understanding something.
Parameters are
char *
, notchar **
. Swapping the pointers in the function won't do what you hope.Were you able to figure it out? I changed the tests to use char** for their arguments and that worked all the way up to the "uncheatedly" test which it failed.
@Root-Exec. Find another way to exchange the content of the buffers you are given. Don't use
**
.As for my OP, that still stands. I think the Kata description should clarifiy the point about strings of different lengths. Meanwhile, tests work OK because even strings of different lengths are within equal sized memory allocations so...
This comment has been hidden.
Figured it out. Nvm.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Please, C Translation
P.S: No merge conflicts!
Thanks!
Python translation. Please, review and approve (the author is inactive).
Bumping translation.
This comment has been hidden.
That's not an issue.
I agree with everyone else, it just needs more tests. And maybe a few random ones.
Added.
Thank you!
This comment has been hidden.
This comment has been hidden.
Insufficient tests
Dup.
This comment has been hidden.
Kata is missing test cases.
Dup.
.
This comment has been hidden.
You have to modify the array referenced by
other_array
. Variable assignment doesn't achieve that. For a simplified example:The value of
a
won't change in the above snippet. Because you just reassignedb
to something else. You have to use array modifying functions in order to change the underlying object instead of creating new ones. For example:This will change
a
to[3, 4]
.Much appreciated.
There are not enough test cases, it's possible to pass this kata by hardcoding array values.
Dup.
.
I do not like that this is implemented as an extension to the Array class since the method is destructive to both the object array and the argument array. It is really bad form for a method to alter its arguments.
Ruby convention is that "a method with an exclamation point or bang is considered dangerous" (http://docs.ruby-lang.org/en/trunk/syntax/methods_rdoc.html). So on the contrary, it would be really bad form to name the method
exchange_with!
if it were not actually dangerous.Many of the built-in Array methods are already destructive, such as: []=, clear, collect!, compact!, concat, delete, delete_at, delete_if, fill, flatten!, initialize_copy, insert, keep_if, map!, pop, push, reject!, replace, reverse!, rotate!, select!, shift, shuffle!, slice!, sort!, sort_by!, uniq!, unshift.
The point is that those methods may only modify self but they don't modify its arguments while
exchange_with!
modifies both.The description is still not clear enough. I have no idea what you want me to do. I had assumed that you wanted to exchange the items within each array so that the arrays basically switch identities, but apparently you want something to do with reversing.
Sorry sir for the late reply. I've updated the kata description. Thank you guys for all the feedbacks.
.
The instructions could be more elaborate. Describe the task with words, not with a code example.
Sorry sir for the late reply. I've updated the kata description. Thank you guys for all the feedbacks.
The description is not clear on what is required. If "Room Exchange" is a common programming challenge, it's not common enough to show up on the first page of Google search results. What inputs are expected? What outputs are expected? What does "Enter from front door & exit from back door" and "Enter from back door & exit from front door" mean? Is the goal to take two arrays, A and B, and put the contents of A in B and the reversed contents of B in A (and discard any
nil
s that are encountered)?Also, failing a test case only outputs "no". The failure messages need to be a lot more informative.
Thank you a lot mlabrum. It's my first kata. I've updated both the description and failure messages.
It's looking quite a bit better now. After I stopped being dumb with my code, this kata wasn't too bad. Curiously, if you try to do
self = other_array
(or any such assignment toself
), the failure text is justno
(and anyputs
statements are blocked), but if the error comes from not switching things over correctly (e.g., not reversing the array) then the failure text is informative. So I learned that you can't naively doself = ...
, which is good to know.My only suggestion now is to add a few more test cases. Off-hand, I'm thinking the following cases would be good: (a) have one or both arrays be empty, (b) have an array contain sub-arrays (e.g.,
my_array = [1, 2, [3, 4], 5, [6, [7, 8]], 9]
), and (c) if possible, have a few cases of randomly generated arrays.