6 kyu

Simple array rotation

61 of 698KenKamau
Description
Loading description...
Arrays
Algorithms
  • Please sign in or sign up to leave a comment.
  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • IntuCode Avatar

    I just want to say this is the one of the most beautiful kata I've done. Very originnal yet requires some thinking.

  • trashy_incel Avatar

    please, C translation

  • trashy_incel Avatar

    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.

  • once_upon_a_potato Avatar

    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.

  • dagolinuxoid Avatar

    Nice kata. BTW. Did you see Unnamed's solution?

  • Unnamed Avatar

    Haskell random tests: [0,5,7,9,4] It's not a valid list.

  • Unnamed Avatar

    Haskell random tests generate lists of length less than 3.

  • lbvf50mobile Avatar

    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"

  • lbvf50mobile Avatar

    This comment has been hidden.

  • Unnamed Avatar

    [7, 12] is both ascending and rotated descending...

  • JohanWiltink Avatar

    Description could really do with a bit more detail.

    We cannot be sure there will only be Numbers 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.

  • JohanWiltink Avatar

    From the JS Example Tests ( ETA: it's in the Submit Tests also ):

    Test.assertEquals(solve([12,7,1,2,3,4,5]),"RA");
    

    Either the sort order is weird or the rotation is weird, both of which have counterexamples in other tests.

    Is this test really correct?

  • Blind4Basics Avatar

    Hi,

    • you should say in the description that there will never be an unsorted array
    • (...'might be (more!) interesting if there could be unsorted arrays too!)
    • you have to say that the sought orders are strict (never two values equal)
    • (...'might be interesting too... ;o)