2 kyu
Cut the cake
306 of 682myjinxin2015
Loading description...
Puzzles
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.
Great and very enjoyable kata! I felt like my solution was very inefficient yet it turns out it was fine.
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!!
In your example, which solution is recognized by tests as valid, and which as invalid?
I think (I cannot remember exactly tho) that if the first pieces are equal, need to pick the solution where the second piece is wider, and if the second pieces are also equal then the solution where the third piece is wider, etc. So in your example, pieces 1 and 2 are identical, but piece 3 is wider in solution 1, and narrower in solution 2, which means you should pick the solution 1.
Does this match your observation?
Hi,
the first one, with 3rd piece 16 width x 3 high size. And yes, if I choose the solutions with the "widthest pieces as much as possible in the begining", it passes..... maybe we should add this restriction to the instructions?
Thanks for the kata!!
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
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.
Yes, this appears to be the case. However, what defines the order of pieces in the solution? For example in a 6 x 7 cake that could be cut as follows:
Would piece 2 or piece 3 be considered the second piece?
answered here
( yes, it should be in the description )
This comment has been hidden.
This comment has been hidden.
I think it asks to sort the pieces w.r.t. locations of top-left anchor points of the rectangular regions. (Not the locations of raisins w.r.t. top-left point of the whole cake!)
Very nice and enjoyfull kyu but it is to easy for 2kyu.
How are the difficulty values set?
I wonder if the true difficulty for any rated difficulty level tends to drift over the years. I.e. this puzzle is from several years ago; maybe 2kyu was appropriate difficulty ranking when it was written but is no longer so.
Ranks are drifting, yeah. Sometimes a lot. This one would be 4 nowadays, I guess...
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..
помоему в тестах ошибки мои куски шире чем в ответе как это понимать: Cake: .................................... Cake: .................................... Cake: ..................o................. Cake: ......................o............. Cake: .................................... Cake: ....o..........................o....
Expected: ......... ......... ......... ......... ......... ....o.... .................. .................. .........o........ ......... ......... ......... ......... ......... ....o.... .............o.... .................. ..................
Actual: .................. .................. .........o........ .............o.... .................. .................. ......... ......... ......... ......... ......... ....o.... ......... ......... ......... ......... ......... ....o.... false
It looks to me like you are returning the correct pieces, but in the wrong order
Да вы правы!Спасибо!
Very fun kata, however, I think its easier than 2 kyu
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?
When pressed "Test", your solution is tested through fixed small number of tests, but when you press "Attempt", your solution is tested through lots of edge cases and random tests.
In anycase, that's not an issue.
I know, and also exactly this tests in "Attempt" was marked as failed. I figured it with output in console all input data. More strange that 1 test marks as Passed and failed in one time.
Awesome Kata, really enjoyed it
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.
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
speed difference in Java and Python/Ruby
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...' '....'
Given two solutions, you should pick the one with a wider first row. In your case, the first two slices are the same, but the last two slices could be cut two ways, and your solution has the less wide third slice.
This comment has been hidden.
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.
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.
Agreed. This ambiguity had me scratching my head for a while.
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. . . . . . . . . . . . . . . . . . . . . . . . ]
cut evenly :)
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
This comment has been hidden.
(deleted: double post... :/ )
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.
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
know cw issue, not related to the kata. You just gained the right to get double points and progress, resubmitting your solution.
I don't understand exactly what you mean with your sentence about "ranodmTests_500" tho. But if you fail taht test, I'd rather bet on a mistake in your code rather than an actual problem ith the kata. Like...: you forgetting to clear a variable between two calls or something like that.
no news, closing.
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?
considering the requirement, you have to find what kind of checks you do that are actually doomed to lead to a dead end. Prune your implementation from those cases. The reference solution (mine) passes the tests in 3,7s, compilation time included. So you're clearly missing one (or several) important "simplifications". ;)
Thanks a lot. After thinking a bit more about my solution I found that I checked some cases several times. Now my solution works and finishes the test also in about three seconds.
No solutions should have been harmed in upgrading this kata's Haskell version from 7.x to 8.x. We apologise for any inconvenience.
Otherwise, a really nice kata!
This comment has been hidden.
This comment has been hidden.
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.
I don't know which language you are using. And, I don't know what the point of your comment is. ;-)
Not an issue.
If it's practically impossible to pass all the tests with that, it's not a problem.
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
Ruby translation
;)
Approved. Thank you for your hard work O_o
fork published, please approve (just a small typo in the formatting of the displayed string, in case of a wrong result. It's already working, but well... missing the "n" of one line feed...).
Are you publishing the edits as a fork instead of editting the kata directly to get another +256 honor? >_<
I do that to avoid entering the edit panel because I have a java trnaslation on the run yes. :p
EDIT: oh, and btw: considering all the work I already did on cw, fixing numerous katas, I don't see where the problem would be in wanting to preserve some katas for other languages I could learn later (FYI, I'm not eligible anymore to more than 50% of all the purple katas I already completed. When you'll be at that point, you'll be able to complain. ;p )
Erm, but translating a kata after you've edited it does give you honor, doesn't it?
Also, you can avoid the problem by completing the kata in all languages you'd like to get rank in and then writing translations (in your case, Python and Ruby - done; Java - you should get the honor for translation anyway; other languages - not interested).
unfortunately no: once you entered the edit panel, you loose the eligibility for honor or % progress in any languages. Same for translations you could do after that: you do them "for free".
This comment has been hidden.
I've changed words
"the order"
to"the order of pieces"
in the description. Thanks for your feedback O_o Happy coding^_^
C++ translation published
;-)
Fun kata, but definitely not worthy of 2 kyu.
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:
The Haskell version actually does this; I just figured out the JavaScript original does not.
Myjinxin, should it not?
Ok. Added. Thanks. O_o
wow, that was fun and easier than I expected
This comment has been hidden.
Hacking that right back at cheaters is quite easy actually (
Object.freeze(Math)
). Thanks for reporting it.NyxTo
does this more often; s/he may need reporting to Jake.First time for a last year I have to think. Nice Kata!
Happy coding
^_^
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 👍)
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.
Approved
Thanks ;-)
Like! :]
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.
Did you also follow the order in which the pieces should be cut and ordered?
See the question I raised below :)
I did see your comment and follow it. However, there are cases where the following are both valid solutions:
In that case, both solutions are valid, and both have the same width for the "first" element.
The comparison is done recursively.
A more appropriate wording would be
select the one with the largest width of the first element of the array in which they differ
:)Ah! Makes more sense, will try that!
What should be the output order for cases like this?
The output order for these kind of complex cases are not very clear.
from up to down, and left to right. just like the order when travel 2D array. sorry, I have no time to improve the description now. I'm busy and busy...
1 2 7 3 8 0 9 6 4 5
That shouldn't happen according to the Description:
If that occurs as an actual test case, then it's a bug.
It's a hypothetical situation.
The point is that the description didn't mention the exact order very well :(
Haskell translation.
Kindly review, and comment or approve.
Approved. Cheers ;-)
That was fast.
I wish I had written it in the two minutes it took you to approve it! ( More like two weeks. :S I'm not really fluent in Haskell. )
Anyway, thank you. And maybe we can stir up some interest. It's a very fun kata. :]
I just changed my rank assessment from
3 kyu
to2 kyu
because this one was much more difficult compared to most3 kyu
. I hope this motivates more people to try :)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 :)cake
looks right having same width for every row<font>
element because it's obsoleteOK, copy&paste them in the test code, thanks ;-) I don't care about this. It's just a fancy thing. In fact, not many people actually pay attention to this pattern ;-)
This comment has been hidden.
Any suggestions are welcome
^_^
"I need your brain, man" -- Sounds like an alien zombie:]
Good :) Just wanted to make sure because I know you're really busy man. Busy maintaining few hundred authored katas while creating some new ones, finding a beautiful girlfriend, helping your daughter with her math tests... Thanks for your great katas, I like how they're unique and requires more thought. I'll continue to help whenever I can by testing and leaving feedbacks :]
I need your brain, man --myjinxin2015 said ( ๏w๏) ((°o° ;)
Is it finished now, all tests complete and correct - can i start coding now or next time:-)?! Really nice to see that there are some more now who recognized these awesome katas (in the past i often solved them first);-)! @kazk, you forgot to say that he has to repair his UFO too, which takes most of his time:-)... PS: Another old and good kata (only one solution:-(): https://www.codewars.com/kata/play-flappybird-advance-bravely
No, That kata has not been so good since CW abandoned its support for special characters :( My personal advice to solve this: https://www.codewars.com/kata/ins-and-outs-play-game-series-number-6 Maybe one day this will not work too :(
Yes, you are right, but before i looked at "flappy bird" and all characters were ok;-)... Your personal advive... i know, started it months ago, but never completed:-(... Now my code is too old, don't understand what i did (some things are missing, parts work), so only complete new code could help me:-)... The (generally) problem is: This kata is "really difficult";-) and there are too many new katas at the moment (and too many different languages to work with - i often change the language)... Last time i had less time and i'm a little bit lazy too (perhaps i solved too much katas:-)) - next time... i don't know;-)
I recommend that kata just because it's a bit similar to this
"cake"
. Yeah, it's a bit harder than this one. 2kyu? maybe 1? who knows.. If no one has solved it and voted to help it out of the testing process, it will always be 9kyu=_=
More than once thought: If the kata created is so difficult that no one has to deal with it, it doesn't make sense. Maybe the kata such as the"exclamation mark series"
is a better choice. I created that series(18 katas) spent only an afternoon. Simple and quick ;-) But I know that's not what I want. I just want to find some fun in the process of creating, solving and sharing kata, that's all. Please forgive an alien who keeps nagging, maybe he's really old^_^
@smile67, Do you still remember thegoal
I have said? Yes, 1000 kata. I finished 40%. A bit tired.. ;-)The rankings of your katas are often too low, your 6 or 5kyu katas are often more difficult than some other katas ranked 4 or 3kyu. Today there's one new 2kyu kata and i solved many of your katas which where harder but ranked much lower. So perhaps sometimes my mistake to give a first ranking (often solved it first) which was too low compared to others and next one chooses same ranking (for me often the problem is/was that the code is simple, but the idea behind is harder, so what's the real ranking - there are some rules for the ranking?!). A problem is that there are many new katas per day which are really simple, so often these simple ones are the first choise, so the harder ones get older and older and at the end nobody remembers (me included)... Nobody is able to solve all of them and often only the "quick 3 points" for simple betas count. So it's not so easy to find the right balance between all, simple, hard, language, new, old a.s.o. So my intension is to say, that "no solution" doesn't mean that it is a bad kata - so don't be disappointed. It's not always easy to concentrate on difficult katas beside work and other private activities (hope there are some others, beside flying your spaceship;-)). And last but not least it's (only?) fun here and your free time is not always the time to rack your brains:-)! 1000 katas... i remember! Seems stressful to me:-)... Publish katas as long as you have fun, so surely 999 would be ok too;-)
@myjinxin2015, Thanks, I bookmarked "Ins and Outs". I'll look at it later :)
Maybe you've reached your goal of
1000
katas already if you kept making katas like "exclamation mark series" and probably be 1st on the leaderboard. Thank you for not doing that and glad to know that you want to and are having fun doing. Authors of difficult katas are rewarded much less than they deserve :( Difficult katas get buried under new easy and not so unique katas produced everyday and becomes harder to find. At the same time, I'm not against duplicate or simple katas because repeated work does help you sometimes (and easy points while waking up :p)@smile67, I believe tests are correct. No errors during tests and 2 solutions so far agreeing with @myjinxin2015's solutions.
I completely agree with you on this. The rank depends too much on "who" ranks it. I always have trouble ranking and often find myself being "Lowest Assessed Rank". Maybe I'm following those bullet points too much to avoid being subjective.
I'm surprised to see Boolfuck out of beta already (5 very satisfied and 5 rank assessments are enough?).
@kazk, i was surprised too that the "Boolfuck kata" came out of beta with these less votes, never saw such case?! Generally i often don't want to vote katas ("very" ok, but rank??) because i'm often to low... On the other side authors want/like votings and ask...;-). For me the rules for ranking are not good enough, they don't work for each kata (and each language for example "SQL"), so at the end the ranking is really very subjective, depends on personal experience, knowlede of algorithms, some other points... probably older katas with higher rankings have "more realistic ones";-))... To get new 1kyu level katas is nearly impossible, i think... (perhaps only for combinations of many single and difficult tasks;-))
@smile67, I saw you in "Scooby Doo" kata :) I avoided ranking because my solution was probably not as the author wanted, but ranked 7 kyu after being asked. I just hope it doesn't affect others' votes much. Ranking is really hard. Sometimes I spend more time ranking than solving :| I agree with you about languages. Ideally, kata should have independent beta process for each language and get ranked independently. Strengths and weaknesses of each language are ignored in current ranking system. But doing beta process per language will take too much time :(
Smallfuck is now out of beta too with 8 upvotes and 8 rank assessments. I don't remember seeing katas approved with less than 10 like these, but I just realized that votes are not equal. "power users" get x2/x4 voting power?
I approved Smallfuck. But Boolfuck was approved with only 5 upvotes and 5 rank assessments. But the ranking was all the same: 2 kyu. Maybe it is needed to have 5 same rankings to get a kata approvable.
@SteffenVogel_79, thanks for the info and approving. Good point, I didn't think about that. So, Smallfuck required few extra because I ranked it 5 kyu :o
@smile67, @SteffenVogel_79, I just found this GitHub issue (feature request) #757 by @donaldsebleung (I was impressed by how @donaldsebleung presented the idea :))
According to this comment by @jhoffner, this change was applied about a month ago.
The first time I saw this rule, Jake was always secretly changing something ;-)
Strange;-)... My second puplished kata ("Parsing and..." - one year old) fulfills these rules for "Purple" but still needs "ranking and feedback"... Perhaps this year it comes out of beta, probably not many solutions are missing - today there are some more C# guys at cw;-)
Thanks @kazk. Very good information.
@smile67: It is approved now! I deleted my ranking and re-set it and then the kata became approvable. :thumbsup:
Wow;-)... Many thanks for the quick approval... just wrote via whatsapp to ask what happend:-)! Perhaps i have to look for some other older katas, but i think that's all now;-)...
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 :]
Well, thanks ;-)
O. M. G..
That took a while. And I was lucky to get it submitted, because my solution is a lot slower than yours.
Do you found any bug here? I'm care about the correctness of the test code ;-)
I have found no bugs. :]
(That statement worth what you paid for it. :P But I don't think there are any.)
Still thinking how to approach this...is this valid "cut"?
Yes. It's a valid cut. But my "cake" is always larger than all raisins.
I'm not sure if i should start it... i don't like raisins... perhaps i wait until i get an apple cake??? But seems intersting:-)...
@myjinxin2015, my first attempt failed on "A complex example" :( I'll try again later.
;-)
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.
Problems related to Chess Board has a loop structure like:
Or atleast throw me some hints, thankyou :)
My idea is to use recursion (maybe others have a better solution). Specifically, for example: a large cake with 4 raisins, so you need to cut 4 pieces. Cut a small piece of cake first, and then judge whether the rest can be cut into 3 pieces. And then cut the rest by a recursion process...
There is no better solution than recursion. :D
Solution may not always be to start with cutting a piece with only one raisin though. Have to allow for solutions which start with cutting into pieces containing more than one raisin each. But you should always cut into pieces that have the correct total size for the number of raisins in it, which is invariant and can be calculated at the beginning, then work on all pieces util you have reached the base case for all pieces. Classical backtracking with recursion.
Great kata again Myjinxin!