2 kyu

Cut the cake

306 of 682myjinxin2015
Description
Loading description...
Puzzles
  • Please sign in or sign up to leave a comment.
  • AdiPassover Avatar

    Great and very enjoyable kata! I felt like my solution was very inefficient yet it turns out it was fine.

  • lfcanals Avatar

    Hi, sorry but there are cases with several solutions that are not properly recognized. For example: Testing for: cake = .................................... ..............o..................... ......................o........o.... .................................... ......o............................. .........o.......................... .................................o.. ....................................

    There are two possible solutions verifying the requeriments: 111111111111111111111111222222222222 11111111111111o111111111222222222222 3333333333333333444444o42222222o2222 333333333333333344444444222222222222 333333o33333333344444444555555555555 666666666o66666644444444555555555555 666666666666666644444444555555555o55 666666666666666644444444555555555555

    111111111111111111111111222222222222 11111111111111o111111111222222222222 3333333344444444444444o42222222o2222 333333334444444444444444222222222222 333333o34444444444444444555555555555 333333336o66666666666666555555555555 333333336666666666666666555555555o55 333333336666666666666666555555555555

    The test says "Test Failed" because it's able only to identify one of both valid solutions.

    Is there any other restriction for the valid solution missing?

    Or maybe the tests should check if the first piece is as widthest as possible, if the size of all pieces are the same, the have a raisin and when you join in order you have the pie....not just expecting a fixed solution...

    Thank you!!

    • L
  • behan Avatar

    For such great katas im on codewars! tip for those who stuck: select the one with the largest width! from top to bottom and from left to right! gl

  • BobotheClown555 Avatar

    There are missed valid solutions even in just the 3 provided test cases. The instructions specifically say that when there are multiple solutions, to choose the one such that the first piece width is the widest, but in the second test case (C++), there are two solutions such that the first piece has the full width of the cake. In the example given in the instructions, one of those solutions was missed. In the third test case, it looks like there are quite a few valid solutions. I'm still working on this one but my guess is it will probably be more fair to say that the valid solution should have, perhaps, the highest first piece width, and then the greatest average width if there are multiple such solutions?

    EDIT I can confirm after some more testing that the rule for the correct solution is the one such that it has the widest pieces in the lowest unique index in the solution vector. For example if two solutions s1 and s2 both have a width 8 piece in their first index, then s1 would be correct if it had a wider piece in the second index than s2, and if those were the same continue on to piece 3, etc. The description should state this explicitly and also add in the 4th correct solution to its example for selecting the correct solution, that shows exactly this scenario where the solutions differ only in the width of pieces 3 and 4.

  • Ricardojorge512 Avatar

    This comment has been hidden.

  • fstasel Avatar

    This comment has been hidden.

  • Persa Avatar

    Very nice and enjoyfull kyu but it is to easy for 2kyu.

  • wickedposh Avatar

    Test Failed Expected: [ ................ .....o.......... , ................ ...............o , ........ ........ ........ .....o.. , .... .... .... o... .... .... .... .... , .... .... .... ..o. .... .... .... .... , ........ ........ ...o.... ........ , ................ ...............o , ................ .o.............. ] Actual: [ ........ ........ ........ .o...... , ........ ........ ...o.... ........ , ........ ........ ........ .....o.. , ........ .....o.. ........ ........ , ........ .......o ........ ........ , ........ ........ ........ .......o , .... .... .... o... .... .... .... .... , .... .... .... ..o. .... .... .... .... ] I just wondered..do I have to cut the cake in the specific way? I think my result is also correct and the answer is not the one and only one way..

  • Shadowof1986 Avatar

    помоему в тестах ошибки мои куски шире чем в ответе как это понимать: Cake: .................................... Cake: .................................... Cake: ..................o................. Cake: ......................o............. Cake: .................................... Cake: ....o..........................o....

    Expected: ......... ......... ......... ......... ......... ....o.... .................. .................. .........o........ ......... ......... ......... ......... ......... ....o.... .............o.... .................. ..................

    Actual: .................. .................. .........o........ .............o.... .................. .................. ......... ......... ......... ......... ......... ....o.... ......... ......... ......... ......... ......... ....o.... false

  • Scheir Avatar

    Very fun kata, however, I think its easier than 2 kyu

  • SvechAS Avatar

    I'm not sure what's wrong with my solution. It must work and do all right, when i press "Test" button - it passes all basic tests, but when i press "Attempt" button - it show "Passed: 2 Failed: 2", every test marks red color, but after every test i got label "Test Passed", and also at end i got message in log "Congratulations! You have passed all the tests! I'm waiting for your feedback, rank and vote.many thanks! ;-)". I got points for solving this kata, can see other solutions, but can't send my solution. What can it be?

  • Diego-Mc Avatar

    Awesome Kata, really enjoyed it

  • Alfabetix Avatar

    Extremely fun to solve, but I found that it was to easy for a 2 kyu, the other 2 kyu I solved it was way much more complicated.

  • GorVictor Avatar

    Note says - from top to bottom and from left to right in cake: [.o....o.\n.o....o.\n........\no..oo..o\n] expected: [".o..\n","..o.\n",".o..\n","..o.\n","..\no.\n","..\n.o\n","..\no.\n","..\n.o\n"] but got: [".o..\n",".o..\n","..\no.\n","..\n.o\n","..o.\n","..o.\n","..\no.\n","..\n.o\n"] but the rule - from left to right and from top to bottom

  • AyushBk Avatar

    speed difference in Java and Python/Ruby

  • pheromo Avatar

    In this example case,

    cake = .o...... ......o. ....o... ..o.....

    there are multiple solutions. But I don't know why the following solution is not accepted:

    '.o......'

    '......o.'

    '....' '..o.'

    'o...' '....'

  • gjenkins Avatar

    Hi, I have added a Go translation for Cut the Cake. This is my first translation of a kata. I did modify description for go, I don't know what needs to be done to have the new description only show for go.

  • Hippunky Avatar

    It's important to better describe the correct 'ordering' of solutions - the implication was that it was just the first slice width that mattered when in fact the solutions should ordered using the subsequent slice width (etc.) to break ties for solutions with the same first slice.

  • bruce.bui Avatar

    An example of no solution case: cake = .o.o. . . . .o.o. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    the result should be []

    Why this one has no solution? i can cut it like this [ .o. , o. . . . , .o. . . . . . . . . . . . . , o. . . . . . . . . . . . . . . . . . . . . . . . ]

  • GavrBY Avatar

    When cutting the cake ................ .....o.......... ................ ...............o ................ ................ ................ .....o..o.....o. ................ ................ ...o............ ................ ................ ...............o ................ .o.............. Test Failed Expected: [ ................ .....o.......... ] , [ ................ ...............o ] , [ ........ ........ ........ .....o.. ] , [ .... .... .... o... .... .... .... .... ] , [ .... .... .... ..o. .... .... .... .... ] , [ ........ ........ ...o.... ........ ] , [ ................ ...............o ] , [ ................ .o.............. ] Actual: [ ........ .....o.. ........ ........ ] , [ ........ ........ ........ .......o ] , [ ........ ........ ........ .....o.. ] , [ .... .... .... o... .... .... .... .... ] , [ .... .... .... ..o. .... .... .... .... ] , [ ........ ........ ...o.... ........ ] , [ ........ ........ ........ .o...... ] , [ ........ .......o ........ ........ ] My first element is largest width, but test Failed Help me

  • dasinlsb Avatar

    I think the problem description could be more detailed:

    If there are multi solutions, what if the upper left ones are the same? Then the next one should be compared ,and etc.

  • FlowBreeze Avatar

    I am using Java.I got a strange error in this kata,I only passed this kata once,but when I submit I got an error and I can't see solutions about it,but my honor added.the kata is in my both 'unfinished' and 'completed' tabs.
    I try to resubmit my solution, it always failed on 'randomTests_500', but when I run the wrong kata on my own mechine,my solution get as same as expected.I think that codewar ignore my if statement(my solution doesn't have static but a inner class).I don't know why,anyone helps me?
    my enviroment: jdk1.8.0_201 on linux

  • cMensendiek Avatar

    I am currently trying to solve this Kata using Java. But my code seems to be way to slow. I am only able to get one fifth through the random test of 500 examples. And right now I have no more ideas to make my code seriously faster. What I have found out is that especially the unsolvable examples of widths of 100 are consuming a lot of time. Have others also encountered such problems?

  • JohanWiltink Avatar

    No solutions should have been harmed in upgrading this kata's Haskell version from 7.x to 8.x. We apologise for any inconvenience.

  • hobovsky Avatar
    • Raisins are great, and every cake with less than 10 raisins should be a punishable offence.
    • I've tried running this algorithm against my birthday cake and there was not much left to eat.

    Otherwise, a really nice kata!

  • a10nik Avatar

    This comment has been hidden.

  • Cunicularius Avatar

    BUG REPORT: So, for some reason I'm passing more tests than I'm failing while only returning an empty list on attempt. About 2 to 1.

  • Blind4Basics Avatar

    Java translation. Please review and approve.

    Note: considering the difference in speed between Java and Python/Ruby, I pushed the number of random tests to 500 (tell me if you believe it's too much. My solution passes the 500 tests in 500ms)

    And while doing the translation, I found another small mistake (nothigng really important, but...) in the ruby translation. The fork has been updated.

    Cheers

  • Blind4Basics Avatar
  • Jomopipi Avatar

    This comment has been hidden.

  • C-V Avatar

    C++ translation published

  • pmarshall1993 Avatar

    Fun kata, but definitely not worthy of 2 kyu.

  • meding Avatar

    Fun kata. Perhaps as another type of "no solution" result would be to have the number of raisins not divide the area of the cake.

    Example:

    o..
    .o.
    ...
    
  • bn7q Avatar

    wow, that was fun and easier than I expected

  • cyril-lemaire Avatar

    This comment has been hidden.

  • wtfil Avatar

    First time for a last year I have to think. Nice Kata!

  • docgunthrop Avatar

    Whew! Challenging and fun kata. Took some bit of brainstorming before finally determining a fruitful method; in other words, it wasn't "a piece of cake" 🍰 (though quite satisfying 👍)

  • hufftheweevil Avatar

    I'll be honest: I pondered about this one for quite some time, but once it was approved I gave it some serious thought. It was a lot easier than I expected. And all this talk about the size of each piece, the order, and the exact solution each test is looking for were some hints as to what approach to take. For anyone struggling with that part: Read the description clearly and think about it logically. :) Thanks myjinxin, for another unique challenge.

  • bartavelle Avatar

    If there are multiple solutions, select the one with the largest width of the first element of the array.

    This is not sufficient, I am generating valid solutions where the first element is as large as the expected one, but that differ from the expected solution.

  • Voile Avatar

    What should be the output order for cases like this?

    11227
    38807
    39906
    44556
    

    The output order for these kind of complex cases are not very clear.

  • JohanWiltink Avatar

    Haskell translation.

    Kindly review, and comment or approve.

  • kazk Avatar

    I just changed my rank assessment from 3 kyu to 2 kyu because this one was much more difficult compared to most 3 kyu. I hope this motivates more people to try :)

  • kazk Avatar

    I played with this in kumite and no bugs found yet :)

    One suggestion: Currently cake in the messages ("Testing for: cake = ...") during the test looks uneven because proportional font is used. I wrote a slightly improved version, please let me know what you think :)

    // paste this
    console.log('<p style="font-family: sans-serif; font-size: 16px; color: #cccc00; margin-top: 0; margin-bottom: 0"><b style="color: #00cc00;">Testing for:</b><br>cake =</p><pre style="font-size: 12px; color: #cccc00; margin: 0">' + eee + '</pre>', "");
    // above current
    console.log("<font face='sans-serif' color='#00cc00' size=3><b>Testing for:</b></font><font face='sans-serif' color='#cccc00' size=3>"+ "\ncake = \n"+eee+"</font>", "")
    // and compare
    
    • should still have the similar "look" (color, font size)
    • cake looks right having same width for every row
    • decided not to use <font> element because it's obsolete
  • kazk Avatar

    Thanks for this kata, this took me a while too :) Ranked as 3 kyu. I didn't encounter any obvious errors during submission, so no bugs for now. I'll let you know if I find anything :]

  • JohanWiltink Avatar

    O. M. G..

    That took a while. And I was lucky to get it submitted, because my solution is a lot slower than yours.

  • kazk Avatar

    Still thinking how to approach this...is this valid "cut"?

    cut(['oo','oo'].join('\n')); //=> ['o','o','o','o']
    
  • DivyanshBatham Avatar

    Hey myjinxin2015, Hope you are doing well :D

    I'm particulary new to these kind of questions, infact have never solved any of this kind. What's the thinking process to solve these kind of questions? (A little bit confussing?)

    Let me clarify what I mean, For example:

    • My pattern printing problems normally revolves around nested loops.

        for( var i=0; i<a; i++)
          for( var j=0; j<b; j++)
            // Do Something...
      
    • Problems related to Chess Board has a loop structure like:

      for( var i=0; i<a; i++)
        for( var j=0; j<b; j++)
          for( var dx=-1; dx<=1; dx++)
            for( var dy=-1; dy<=1; dy++)
              // Do Something...
      

    Or atleast throw me some hints, thankyou :)