7 kyu

Rotate for a Max

2,955 of 11,106g964
Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • spyderfalcon Avatar

    This comment has been hidden.

  • sylentdood Avatar

    description is a bit wonky but was a neat problem

    racket is cool yall

  • Natesan Avatar

    This comment has been hidden.

  • St01k Avatar

    This comment has been hidden.

  • demeshko_egor Avatar

    pefrect presentation of the bubble sort in some kind. but first i was very frustrated.

  • VxyX Avatar

    i dont get it... the instruction quite clear for the first example "56789". but how "max_rot(38458215) should return 85821534"? isn't it suppose to be:

    38458215

    84582153 (rotate left)

    85821534 (hold first number) --> this is the answer, so i should stop here?

    85215348

    85253481

    85254813

    85254138

    85254183

  • LeshchuDev Avatar

    nice kata,It was difficult for me but I learned a lot. One question: Does Codewars accept or recognizes js method toSpliced()? I needed to change it on other one...

  • EndyPlus Avatar

    After a lot of attempts, i returned to this kata and solved, im glad.

  • Extend Avatar

    Nice kata. Advice for warriors: you should be attentionally with reading description =)

  • jkimbell Avatar

    Good one, but def harder than 7 kyu.

  • aryuemaan Avatar

    I am getting this error For n = 38458215: 84582153 should equal 85821534 For n = 195881031: 958810311 should equal 988103115

    for first 2 test cases that next two test cases are passed my logic was to store each rotation in the rotations list to keep track of all the numbers generated.

  • anantacodes Avatar

    always tend to get stuck on katas by g964 so much so that everytime i see their question , I go - 'argh, here we go again' . great exercise for the gray matter :D

  • asoro Avatar

    feels like 6kyu to me. I am noob tho

  • AmirTallap Avatar

    This kata is a good one, you just need to focus, at first you will think that the kata is wrong, but after careful consideration, you will know how to solve. The random test cases are near perfect.

  • Nikkorat Avatar

    Test shows that 99249557 should equal 507992495, really?

  • miggycoder Avatar

    Good kata, beginners might struggle with this one since they may not understand what "rotating" the number means. But once you understand the rotating factor, the kata becomes particularly easy.

  • hemamangati1966 Avatar

    This comment has been hidden.

  • Cloud Walker Avatar

    Nice kata. Maybe a bit difficult for beginners though.

  • andr33v Avatar

    Nice kata, it's easy, just look carefully at the description!

  • PR3SS F Avatar

    For all the whiners, yes it's a bit challenging, but over all it does fit 7kyu lvl, so keep your mind sharp and attention to details even sharper. It's easier than some of the 7kyu katas' i've seen. All good, and may the force be with you.

  • thepatrick00 Avatar

    Very satisfiying once you solve it. I finally solved something with recursion and it was this problem :)

  • perezc52 Avatar

    The description of this problem is really bad

  • F3GR Avatar

    This comment has been hidden.

  • F3GR Avatar

    This comment has been hidden.

  • OsmanCanCinar Avatar

    That's not Rotate means......

  • thinker.xt Avatar

    This comment has been hidden.

  • pavloslav Avatar

    It Rust tests generate a warning:

    warning: unused borrow that must be used
       --> src/lib.rs:136:13
        |
    136 |             &digits[i..].rotate_left(1);
        |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the borrow produces a value
        |
        = note: `#[warn(unused_must_use)]` on by default
    help: use `let _ = ...` to ignore the resulting value
        |
    136 |             let _ = &digits[i..].rotate_left(1);
        |             +++++++
    
    warning: `challenge` (lib test) generated 1 warning
    
  • tallodimark Avatar

    missing a lot from the description!!!

  • Arsenator Avatar

    overcomplicated

  • balu9 Avatar

    Description should have been better, I thought the original number shouldn't be considered while calculating the max number. This should be a 5 or 6 kyu!

  • PatrykJagielski88 Avatar

    Interesting but for me it was quite difficult and I think it's closer to a 5kyu or 6kyu.

  • f4nke Avatar

    so bad desc

  • Blind4Basics Avatar

    Ruby 3.0 should be enabled (Refer this & this for more detail)

  • Ne_MoBu_u_Ne_ToNu Avatar

    I have an issue with tests in java. The function's input type is long, but the test's input is represented by java compiller as integer. Could you please do soomething with tests for java?

    16130873362142 cannot be represented as a 32-bit integer (type int). It can be represented as a 64-bit integer (type long). long literals in Java end with an "L": 16130873362142L

  • Strel-Alex Avatar

    Getting the following error. Why max_rot(rnd) should return "r"? n should be a positive digit.

    Traceback (most recent call last): File "/workspace/default/tests.py", line 62, in randomTests() File "/workspace/default/tests.py", line 60, in randomTests testing(max_rot(rnd), r) File "/workspace/default/solution.py", line 8, in max_rot str_n += str(n)[i] IndexError: string index out of range

  • IgorTheOverlord Avatar

    I'd like to have more tests because my code works well on tests but when I try to attempt it fails, it would be nice if I could see a default number and not just what the result should be

  • ilyushal33t Avatar

    my absolutely wrong PHP solution (its not even a solution, i was just testing functions) somehow pass all cases

  • v1taly Avatar

    This comment has been hidden.

  • oldcoder Avatar

    good kata

  • martynov-94 Avatar

    This comment has been hidden.

  • romaxa11 Avatar

    Cool kata with Strange description))) Thank You!

  • ejini战神 Avatar
    • Node 12 should be enabled (Refer this and this for more info)

    • Python new test framework should be used (Refer this & this for more detail)

    • Ruby 3.0 should be enabled (Refer this & this for more detail)

    • Typescript 3.3 or above should be enabled, refer this for more info

  • Guicbdiniz Avatar

    This is not a 7kyu kata. 6kyu min

  • web.borisoff Avatar

    This kata has greatly improved my knowledge 💪. I am very happy! Thanks to the author 👍!

  • nomennescio Avatar

    Issue was marked as resolved by author without any change to the description.

    Here's a suggestion to improve the description:

    Write function max_rot(n) which given a positive integer n returns the maximum number you got doing rotations similar to the above example.

    An example is not a spec. "Doing rotations similar to the above example" is too vague. "the maximum number you got doing rotations"; how do I "get" a number "doing rotations"?

  • nomennescio Avatar

    This kata's description is not even close to a proper spec. The number of people that already solved the kata does not change that fact. Please put at least some effort into it. For a 7 kyu kata, it's not fun trying to discover by trial and error what exactly is asked for.

  • oleksiiB Avatar

    This comment has been hidden.

  • JayYay Avatar

    Bad description... But then again, I don't expect anything more from g964....

  • 1Stas Avatar

    This comment has been hidden.

  • attyhor Avatar

    In Instructions nothing, what should i do with zero. If 0 is first, then delete?

  • imjasonmiller Avatar
  • B1ts Avatar

    Where's the love for Prolog ? ;-)

  • imjasonmiller Avatar

    Fun kata :-)

  • Walrusmunchies Avatar

    This comment has been hidden.

  • Bokkii Avatar

    This is not for help solving the probem. My function is correct.

    The issues are in randomized tests: My value is greater than the expected value, as seen below:

    Expected: {4635994101} But was: {6359411940}

    Expected: {962193428} But was: {994286132}

  • Bokkii Avatar

    Please help!

    I have passed the test case but stuck on random test. Please see the output of the random tests below:

    Time: 6080msPassed: 0Failed: 2Exit Code: 1 Test Results: max-rot Fixed Tests Should Pass Fixed Tests

    Expected: {962193428} But was: {994286132}

    Stack Trace Completed in 686ms Completed in 686ms Random Tests Should pass Random Tests

    Expected: {4635994101} But was: {6359411940}

    Stack Trace Completed in 198ms Completed in 198ms Completed in 884ms

    Language is PowerShell.

  • TYZILLA Avatar

    testing(max_rot(38458215), 85821534) testing(max_rot(195881031), 988103115) testing(max_rot(896219342), 962193428) testing(max_rot(69418307), 94183076)

    These test cases make no sense... the bottom 2 only move the number once and the first two moves twice

    921934286 should equal 962193428 91830764 should equal 94183076 511728027 should equal 571172802 452257820 should equal 452782025 665682451 should equal 666824515

    While these dont even move the first number to the end. What is it that youre asking for????????

  • TYZILLA Avatar

    WHAT IN THE WORLD IS THIS DESCRIPTION

  • a20s11a Avatar

    What is it that I'm not getting? I passed the Test but he Attempt fails (with 100+ successses and 100+ fails)

    I inserted a code to see which number is the input and sometimes the programs expect to have the input as the solution. For example one of my fails had an input number of 62383480048545 and the result was saying "28480048545633 should equal 62383480048545"

    What am I not getting there?

  • AverytheFurry Avatar

    This comment has been hidden.

  • user4896126 Avatar

    please stop allowing rubbish katas like this one on the platform rubbish description as many people have pointed out ruins the experience

  • fibonaccios Avatar

    Very enjoyable, i don't know why people complain...

  • rbolinger86 Avatar

    This comment has been hidden.

  • Koziolek Avatar

    Elixir verion at this moment is broken. When I run Attempt tests I get:

     STDERR
    ** (CompileError) test/solution_test.exs:54: undefined function to_charlist/1
        (stdlib) lists.erl:1337: :lists.foreach/2
        (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    

    That error came from module prepared by author.

  • xspired01 Avatar

    Description is a little vague, though difficult to succinctly describe the question. Maybe update to say something along the lines of: Given a number, rotate the first digit left to the end of the number (12345 becomes 23451). Continuing rotating the first digit left for the length of the number up until the second to last digit (1234 eventually becomes to 45123). Given the new numbers (12345, 23451, 34512, and 45123), determine the largest value.

  • megawatt Avatar

    Are these test cases wrong?

    testMaxrot 1, 38458215, 85821534
    testMaxrot 2, 195881031, 988103115
    

    Shouldn't the output for the first one be something like 85254183? The second one 981318105??

    I am able to get these solutions if I set the rotate limit to 2 instead of length(n)-1, but that is not what the description says

  • mjasnikovs Avatar

    Unacceptable bad description...

  • sarange Avatar

    really bad description

  • shuarey Avatar

    I'm getting a Java 43 error stating that there's a possible lossy conversion from Long to Int. The description is pretty clear that the input will be an int, yet the tests accept Long inputs. I can change all of my types in my internal methods and then cast to an Int in the end, but that seems silly. Is this by design or something that made it's way into the Java version by mistake?

  • rka444 Avatar

    The kata statement says nothing about integer overflows.

    I.e. an input like '8999999999999999999' which fits int64 (golang user here) after the first rotation becomes '9999999999999999998' which overflows and now is -8446744073709551618.

    Depending on how we treat the overflow 9999999999999999998 is either the answer (it is a clear max) or not (it is now negative).

  • stauntonjr Avatar

    rotate for max... again the objective was not clear... i thought it meant rotate digits through the terminating digit. in fact it means you collect ALL of the intermediate numbers too, and then among them (AND the original n) return the maximum.

  • nullwiz Avatar

    Dont solve this kata, in my case i used pop and append, and digits magically increase in the test cases -- also, on some of them which digits do not magically occurr, I test them locally and they work fine.

  • Aslan42 Avatar

    i can't understand, what's problem. "String index out of range: -1". Can someone help me?

  • BobAllan123 Avatar

    The description only says to rotate four times, it doesn't say to continue the pattern over the lenght of the number no matter how long. Please consider updating the instructions for those of us that take insturctions very literally. :) Other than that, nice kata.

  • codespree Avatar

    Can someone help me in this Error. Expected 452782025 but got 405225782 What is the starting number for which i am getting this error so i may exactly know the bug in my code.

  • 7esoterik7  Avatar

    The condition should be explained more specifically. Why in example 5 and 9 swapped?!?!

  • damika Avatar

    Hi, the sample test works fine for my solution -> nevertheless 1 of 22 test crashes whenever I try to attempt the code. Because there is no usefull log of the test result, I can't see which test fails and why. Is it possible to get more information about the crashed test?

  • jerzyjerzy Avatar

    Hello, for input containing many zeros like 1020 you could have two possible ways of dealing with it: (1) 1020 -> 0102 -> 0210 -> 0201 or (2) 1020 -> 102 -> 120. You chose the case (1) but it doesn't have to be obvious. Maybe consider adding a second example to the kata's description to leave no space for doubts. Regards

  • RafaPuff Avatar

    why 38458215 equals to 85821534 after maxRot? I cant understand the task. if we move one position to the left we will have: 8 4582153->85 821534->852 15348->8525 3481->85254 813->852541 38->85254183

  • Dustîngank Avatar

    for c language; I passed all the test case, however, when I attemp it, there is one test case case I can't passed it. It's said: "Excepted 6387336214110 but got 1817467955"

    How should I slove this problem?

  • Darius.V Avatar

    This comment has been hidden.

  • mplewis Avatar

    This comment has been hidden.

  • orangeornithus Avatar

    The description is pretty difficult to get through as non-visualizer since 'rotate left' actually means moving a particular digit to the end, the right. But easy to implement once understood.

  • mortoray Avatar

    The description only says you should rotate three times, it doesn't say rotate over all the digits. Nor does it state bounds such as being >= 0. And it doesn't mention that the original number should be part of the maximum.

  • Insti Avatar

    This is pretty difficult for a 7 kyu kata.

  • TinoC Avatar

    Hi, does anyone know how to print debug output for the C++ interface? cout << "test" << endl; is giving me a JSON error ... I'm just starting on testing C++ 14 on this site and I'm sorta helpless :)

  • Vladpptx Avatar

    This comment has been hidden.

  • masterridley Avatar

    Needs fixed checks for edge cases like ints of "size" 2. My first solution was wrong for such ints but was able to pass the tests!

  • jmorrison Avatar

    99249557 should equal 507992495 This was a pain. The details could be more clear on including the original number, and no it does not say that. It's frustraint when original tests pass and it fails due to a random test not outlined originally when you submit it. I see many opthers had a hard tiem with this too. Just a lttle clearer on using the original number as well.

  • aj_613 Avatar

    Seems like there's something wrong with the test. maxRot(441142049) should return the value 414204941 as the answer -- and it does but I still continue to get this error. "Failed asserting that 414204941 matches expected 441142049."

  • vap Avatar

    When I execute the random tests every 32nd test case run will fail. "Time: 17ms Passed: 31 Failed: 1". I have printed out the input value in these cases, added it to manually executed tests, and each time was able to to run the test succesfully. I'm wondering why it's always 32nd executed test case which fails... I wrote the code in C.

  • user7163583 Avatar

    Typescript compiler can't compile anything because of the following error:

    ../home/codewarrior/solution.ts(2,27): error TS1005: ';' expected.
    ../home/codewarrior/solution.ts(2,32): error TS1005: ';' expected.
    

    It doesn't even compile a blank function that's there by default..

  • Skarlso Avatar

    Hi.

    Does anyone have a clue, how I could debug exceptions?

    It just says this:

    Fixed__Tests ✘ Caught unknown exception Random_maxRot Log


    Locally, I compiled the code, it runs fine even with big numbers.

    Thanks!

  • jco44 Avatar

    Python

    Does "99249557 should equal 507992495" in the test output mean max_rot(507992495) should output 99249557?

    max_rot(507992495) = 99249557 when I run my function locally, but errors in the test case. Could there be an issue in the test case due to the leading 0?

  • guiguzhixing Avatar

    I used C++ to accomplish the function. There is a problem when input is '099249557' . When the input save as 'long long' type , the first alpha '0' will lost. Is there are any other solution ? Or it just the bug of test examples?

  • backwallkid Avatar

    This comment has been hidden.

  • sanny Avatar

    Hello, can you please fix test cases.

    Wrong : testing(MaxRotate.maxRot(38458215), 85821534);

    Right answer is - 85254183

  • DHail Avatar

    This comment has been hidden.

  • john-pick Avatar

    I think the description should changed to explicitly state that your code should consider "n" itself when returning the largest number. It's very frustrating to write a solution that passes all of the initial tests, and then fails on some of the random tests - especially for newer programmers.

  • gawroon7 Avatar

    I keep getting "Caught unknown exception". Anybody? No idea. It compiles and runs when I compile it in DEV-c++

  • spencerwi Avatar

    The Typescript version of this test has errors; the "reference" syntax at the top is wrong. It should be

    <reference path="..." />
    

    not

    <reference path="..." ></reference>
    

    I can fix it in the visible test cases, but when I go to submit, I'm hosed.

  • smcgee31 Avatar

    wow, worked fairly hard for this one and test cases have errors... now what? that kinda sucks.

  • WompWomp Avatar

    may want to give a bit of context because I had no idea what rotating left for numbers was until I looked it up: https://en.wikipedia.org/wiki/Bitwise_operation

  • caesarsol Avatar

    Just learned clojure, any longtime clojurist that can check my style? :)

    http://www.codewars.com/kata/reviews/56a48bc7272cb4e0f000003c/groups/56d7041c3e818628fd000c87

    I like rot and rotn, but I'm looking for a more elegant cycle in the all-rot function.

  • jijiki Avatar

    I get in random tests (python): 99249557 should equal 507992495 99249557 has 8 digits 507992495 has 9 digits

    my code claims that max is 94955792

    All other random tests did pass. Is there a problem with this specific test?

  • minibug Avatar

    I think default test case for java in case

    testing(MaxRotate.maxRot(869219342), 962193428);
    

    is invalid.

    for input 869219342 expected is 962193428 but the most of result of maxRot should be start with 6xxxxxxxx

  • ljromero Avatar

    This comment has been hidden.

  • simplydallas Avatar

    This really doesn't seem kyu7 difficulty to me. At least not for JavaScript. kyu7 is a beginner tier. This is deceptively complex and requires caching results, type conversion, custom value based sorting, and a decent amount of manipulation. Add in the fact that the description is implicit instead of explicit for things like including the original value in the sort options and you are just going to frustrate someone who is at a kyu 7 skill level currently. This should be at least a 6.

  • LDanforth Avatar

    passing 150 tests but failing on some number. "2642376522401 should equal 2642765224013" ??? That's obviously wrong!

    So now I'm printing the input number with my result so I can compare when I get these errors and it appears there is something wrong with the test case:

    My output: 36191144385332 and the max is 69144385332311

    Error: 69144385332311 should equal 69148533231143

    The one consistent thing about this error is that my max result matches the begininng number in the error message. It's very random so I'm passing anywhere from 44 -150 tests before this comes up.

    563692037 563692037 and the max is 669203753 Test Passed

    159043701 159043701 and the max is 590437011 Test Passed

    896304934 896304934 and the max is 963049348 Test Passed

    273293210 273293210 and the max is 732932102 Test Passed

    451496516 451496516 and the max is 549651641 Test Passed

    88700243816673 88700243816673 and the max is 88700243816673 Test Passed

    65879065959482 65879065959482 and the max is 65879065959482 Test Passed

    88361793184682 88361793184682 and the max is 88361793184682 Test Passed

    91556298303742 91556298303742 and the max is 91556298303742 Test Passed

    Random tests ****************** 86924138583362 86924138583362 and the max is 86924138583362 Test Passed

    77490520118683 77490520118683 and the max is 79520118683740 Test Passed

    99069689298951 99069689298951 and the max is 99069689298951 Test Passed

    55180712498677 55180712498677 and the max is 58724986775101 58724986775101 should equal 58729867751014

  • Ab_bh Avatar

    g964 plz look into this pls....

  • Ab_bh Avatar

    for eg: max_rot(38458215),85821534 should be according to test case but here is it done on paper: 84582153 85821534 85215348 85253481 85254813 85254138 85254183 which should be the answer but you can see what test case is .....

  • Ab_bh Avatar

    i think test cases have errors...i mean i can do it in copy and test cases still dont match....i think test cases should be checked again

  • BenjaminDowns Avatar

    I think perhaps one of the test cases is incorrect. I keep failing the 13th test after submitting, but I can't figure out how; and since this is a new Kata, perhaps it's just messed up. If it's my mistake, could somebody give me a hint? Here's what I have:

    function maxRot(n) {
    
      let nArray = n.toString().split('');
      let results = []
      
      for (let i = 0; i < nArray.length; i++) {
        let next = nArray.splice(i, 1);
        nArray.push(next);
        results.push(nArray.join(''))
      }
      
      return Math.max(...results)
    
    }