6 kyu
Simple array rotation
61 of 698KenKamau
Loading description...
Arrays
Algorithms
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.
python new test framework is required. updated in this fork
Approved
I just want to say this is the one of the most beautiful kata I've done. Very originnal yet requires some thinking.
please, C translation
Approved
I've added a test with every arrangement for an array of length 3 to JavaScript. Several incorrect solutions (including mine) have been invalidated. Also updated to
Node 12
, be sure to reset the tests if you train again.Hi, just wanted to suggest a test case. Current test cases lack arrays like [7, 7, 1, 2, 3] where there are two or more same numbers at the beginning of an array in "RA" or "RD" I have seen some solutions fail that.
ive looked at the Python and JS tests and they never generate duplicate elements. it would require a redefinition of the problem anyway, since
[4, 5, 5]
can be seen as bothA
orRD
. i've added this to the descriptionNice kata. BTW. Did you see Unnamed's solution?
Haskell random tests:
[0,5,7,9,4]
It's not a valid list.The random tests are off. I will add some manual cases to resolve this.
Fixed. Try now.
Haskell random tests generate lists of length less than 3.
Thanks. I will resize
Random list length now consistent with other languages.
Kata tests are not cover all cases:
One of my solutions: fails this test describe "Simple array rotation" do it "Uncoveder 3 tests" do
Test.assert_equals(solve([10, 100, 1]),"RA") Test.assert_equals(solve([10, 1, 100]), "RD") end end
But pass the task. Test example created by rollin ASC and DESC arrays.
"ROTATING [1, 10, 100]is ASC" "rt: 1 ar: [10, 100, 1] ac and a>c"
"ROTATING [100, 10, 1]is DESC" "rt: 1 ar: [10, 1, 100] a>b and b<c and a<c"
This comment has been hidden.
@lbvf50mobile, is this something that came up in an actual random test or is it something you are thinking up?
The structure of random tests makes the scenarios you are mentioned not possible. So this is not an issue.
Lastly, please stop posting links to your code and not marking it as having spoiler content. If you do it again, I will have to block your posts.
These two test cases I generated myself from the ASC and DESC arrays [1,10,100] and [100,10,1]
By rolling them using ruby method
rotate(rt)
in for loop wherert
in range0..3
.Here is log from loops.
"ROTATING [1, 10, 100]is ASC" "rt: 1 ar: [10, 100, 1] ac and a>c"
"ROTATING [100, 10, 1]is DESC" "rt: 1 ar: [10, 1, 100] a>b and b<c and a<c"
See my post above. Non-issue.
It's your problem thay your KATA can be SUBMITED by incorrect code. I tryed to fix it, but instead you even could not understand what happens.
As I've mentioned, these tests that you have generated are not possible in this Kata. I avoided such tests.
That's exactly the issue. Why? These are valid inputs.
Do this test posible in kata?
"ROTATING [1, 2, 3]is ASC"
Test.assert_equals(solve([2, 3, 1]),"RA")
"ROTATING [3, 2, 1]is DESC"
Test.assert_equals(solve([2, 1, 3]), "RD")
They failed by my solution to, but KATA is passed.
Unnamed how do you make quatation in converstaiton?
What you see is what you get. It's too late to make changes. I see you submitted your solution; why are you still dwelling on this?
Because I do not whant ERRORS in "problems" on this play ground. It's good that your mistake make KATA pass, but next time you create error that pevent submiting cata, and people will spend vaste time dealling with your agression. Even after 10 posts problem dose not fixed.
With
>
, it's GitHub markdown: https://guides.github.com/features/mastering-markdown/It's never late to add tests. The point of testing is to tell apart correct solutons from incorrect ones.
Unnamed. I got it. thank you.
@lbvf50mobile, I think you are the only one facing this issue. And since you have solved this Kata, I suggest you move on. .
Also, you can always make a kata that works the way you want. Thanks for your contribution
@Unnamed, I can't tell what he's on about. I really don't understand him or what the issue is.
The kumite linked above contains an incorrect solution and some tests it doesn't pass. However, it passes all the tests present in this kata, so these tests should be added or even just all permutations of 3 numbers.
Thanks! This is clear. I will add the tests.
@Unnamed thank you for help in solving this disput.
This comment has been hidden.
Please clarify how this is an issue. I'm not a fan endless links.
these tests are already implemented, at least in the test cases (these are those that I suggested below). So all good.
(note: I just checked in python)
Even if they weren't, this Kata has specific requirements. All other specs are irrelevant.
Hi guys. I add one more Issue because after several hours of coding did not find reply button :)
Anyway, in Ruby it's still pass the KATA with solutions that dose not cover 3 elements rolled ASC/DESC array. I specially wrote some script to generate all this sequence. You can find this test in ISSUE above. + KUMITE with test and SOLUTION that works in current moment while failing this test.
Thank you
[7, 12]
is both ascending and rotated descending...Damn, my fault, I didn't think about that.
For it to make sense, the min length should be 3. I will make the changes.
Updated. Please refresh page.
Description could really do with a bit more detail.
We cannot be sure there will only be
Number
s in the array, sort order is undefined ( numerical or lexicosomething ), not specified what to return if an input array is sorted neither ascending nor descending with or without rotation; if that's supposed to be impossible, that isn't specified ..Even after solving, I couldn't figure out why
[12,7,1,2,3,4,5]
should return"RA"
. The reference solution looks like an incomplete ad-hoc implementation.It's neither adhoc nor incomplete. Description updated.
Let me know anything comes up.
By "ad-hoc incomplete" I meant that the reference solution gave a valid result for an invalid testcase. It seemed written towards the tests instead of the specs.
I still can't figure out how it does what it does. That is partly my problem of course, I haven't spent enough time on it, but it does mean its logic is not clear. I'm pretty sure my code will return correct results for valid testcases, and not return a seemingly valid result for an invalid testcase. I have no clue what yours will do in that situation. That need not be a problem, but you have to be d*mn sure all testcases are valid.
Description still makes no mention of datatypes in the array. String and numbers can both be compared, but sorting can be done in ways that work for strings only, for numbers only, or ( but only if you're careful ) for both. Nobody else seems to be sorting in their solutions ( yet ), but I still think this is an omission in the description.
From the JS Example Tests ( ETA: it's in the Submit Tests also ):
Either the sort order is weird or the rotation is weird, both of which have counterexamples in other tests.
Is this test really correct?
Hi Johan, I've added this to the description:
Much clearer?
[7,12,1,2,3,4,5]
is different from
[12,7,1,2,3,4,5]
Dat^
Thanks guys. There are too many issues. Pulling it down to review.
It should be good now. Please confirm.
Yep, looks good now. Thanks!
Hi,
Currently, my beautiful solutions couldn't handle such cases:
to add?
EDIT: (but this one does... :p )
EDIT²: being at it, you should add the minimal edge cases, even if...:
I've added the edge cases. Thanks for this.
Unfortunately, unsorted arrays would not fit in this Kata, unless if the idea is for them to return "impossible". Is this what you had in mind?
Yeah, something like this. But that will make the solutions longer... ;o
It's not an issue to include this, but the biggest problem is that it will invalidate all submitted solutions.
has you want, but now that you have a consistent/detailed description, I'm not sure that's usefull.
Ok. That's fine.