3 kyu

Fabergé Easter Eggs crush test

165 of 1,870Ivana
Description
Loading description...
Mathematics
Dynamic Programming
Performance
Algorithms
  • Please sign in or sign up to leave a comment.
  • gkocot Avatar

    I think something wrong with tests. For n=311 m=10131 the test says Expected : 71692423655005205742475058887780204076478173193756056534361211129546043664445431944499667343853437837654574420941236308628252496657306440547150042542033422966836724604589618585313406081996653652790266390363056344043348948460554622622321171105487547727180837279888801878208802638642014343289117270679561876255479945479493366274871820692161157345919355451766369038588713612753294660349103505913526811646787927664100720765220490895831907659845589011856751027720648370221163404996407536536129106286633176735546895953041399202973489205488615661260572453354171008663345444479871804393330314581222773072596927 to equal : 3

  • PetrovGleb Avatar

    Worst description i've ever read. sorry.

  • YslamB Avatar

    This comment has been hidden.

  • P1GAS Avatar

    Looks like there is wrong mark in description in maxmimum word

  • cainytheslave Avatar

    Dead problem 💀

  • GolfJuliettWhiskey Avatar

    Extremely poorly explained. Misses the point of programming exercises entirely, as programming knowledge is completely secondary to the task at hand.

    If you're interested in Katas that involve programming, skip this one.

  • Reamuji Avatar

    assume we have 2 eggs and 4 try

    from what i understand, the decision tree behind the answer is that

    down is break, rigth is survive
    4 ----- 7 --- 9
    |       |     |
    1-2-3   5-6   8
    

    the answer is 9

    but if it did not break at 3 or 6 or 8, we know its 1 above it since we already tested 2 above it so the decision tree should be

    5 ----- 9 --- 12
    |       |     |
    1-2-3   6-7   10
    

    the answer should be 12

    im not sure if i misunderstand it or i should put it into issue

  • sierikov Avatar

    Am I doing something wrong or are we restricted to using only BigInteger?

  • jasong-au Avatar

    Took me a minute to understand the question, but the test values helped. The values are:

    • n - number of eggs available
    • m - number of drops possible (any more would cause his heart to break)

    So for example if the values were n = 1, m = 100, the answer would be 100. Just start dropping your one egg at floor 1 and continue up until it either breaks or you run out of tries. So you can give the exact number for any floor up to 100. The actual floor might be 2000, but you can only verify up to 100 with one egg. If you start on any other number, for example floor 2, the egg might break. Then you know that floor 2 isn't safe, but you aren't sure if floor 1 is safe or not, so you can't give a correct answer.

  • ZhirnovPN Avatar

    I have a problem with random test My code work with all values

  • matt90hz Avatar

    This comment has been hidden.

  • Ruslion Avatar

    OK. So, I finally solved it in python with dynamic prorgramming and gmpy2 library. But it turned out there are simplier solutions if solved mathematically (facepalm).

  • Ruslion Avatar

    How many random tests? I beat 7 random tests maximum.

  • ahagert Avatar

    I've read there were made only 69 Fabergé eggs of which 57 survive today. So if you do a test with more than n>57 some of them are not real Fabergé eggs ;-).

  • nikzjon Avatar

    I have solved the problem in golang. Optimised it using 2D array caching. But it is failing for last two data input only in the test code. They are (310, 512) and (494, 500). Not sure why. It must be something to do with golang math/big library. Not sure what. Any ideas?

  • Ulisse Avatar

    Sorry it's my fault for sure but I can't understand the explanation of this kata. at a certain point the text states "[...] if they(the eggs)'re thrown from a certain floor or below, they won't crack. Otherwise they crack. [...]" Should I desume this height just from the value of N and M?

  • Vindicar Avatar

    Description should better explain how the number of eggs N is different from the number of tries M. As far as I understand it, it's not a problem with two parameters, it's a problem with one parameter: min(M, N) Or do we get M tries per each egg, so it's M * N?

  • Kaî Avatar

    This comment has been hidden.

  • dmitryloskutnikov Avatar

    Start 0 floor.

    0 tries. A(0,1), A (0,2),...,A(0,n) = 0.

    0 eggs. A(0,0), A(1,0),... A(m, 0) = 0.

    1 eggs. 1 tries. A(1,1) = (A(0,0) + 1)

    1 eggs. 2 tries. A(2,1) = (A(0,0) + 1) + (A(1,0) + 1).

    .....

    i - tries, j - eggs.

    А(i,j) + X = A(i+1,j)

    X = A(i, j-1) + 1

  • lamdann Avatar

    We have N eggs and M attempts, Who determines when an egg will break?

  • biboon Avatar

    Tough but nice one !

  • bigcacturne Avatar

    I solved it recursively using memoization, but I don't know how to use the BigNumbers module. I just have to figure out how to do that and hten i can submit

  • iSmurfing Avatar

    I got a question... I know there are some different ways somenone can solve this problem... I choose the dynamic programming just to practise it. Despite the fact that, I follow very carefully the theory and some articles I always take time execution error. Is there any way to solve this problem using dynamic programming or i should look for another way to approach the problem?

  • spyhere Avatar

    The more eggs and tries you have the higher floor it will be... So I guess the specific math formula is supposed here other than that I see no sense. height 2 14 = 105 height 7 20 = 137979. And what's gonna be the floor if eggs: 10, tries: 3? This is a pass, sorry...

  • Xurxo654 Avatar

    This seriousTests case is killing me. I can't figure out how to optimize my solution enough to pass.

    I've got the obvious case of m <= n covered to knock out half the calculations. I've also got m - n == 1, m -n ==2 and m = 2n + 1 to knock out more calculations but I cannot figure out how to reduce the calculations when m is much greater than n.
    Can someone give me a hint?

  • Demo30 Avatar

    For people who may also be confused by the "target floor can be any floor between 1 to this maximum height" => in cases when it is not possible to throw an egg, the answer is not 1, but 0 - existence of the target floor from which the egg will not break is not guaranteed. There may be 0 such floors. The description seems misleading.

  • IvanHernandezA Avatar

    This comment has been hidden.

  • darkmain Avatar

    This comment has been hidden.

  • rospolis Avatar

    This is a very difficult kata. I solved it only ... after solving 1kyu continuatin of this kata. So my advice for anyone else struggling (like I did for days) would be to think how you would solve the related 1kyu kata which would enable to rule out some of the standard approaches that should be more than sufficient for this 3kyu kata but which in fact are not. Also tags on ths kata are incorrect and while you might/should start with writing the equations that would be used for Linear Programming this kata is not solved by Linear Programming.

  • user3342336 Avatar

    I can't understand the description...

  • el-f Avatar

    Description code blocks made only for haskell, missing other languages.

  • AshotVantsyan Avatar

    This comment has been hidden.

  • Nam01ar Avatar

    This comment has been hidden.

  • ansis m Avatar

    This comment has been hidden.

  • Symphoniacus Avatar

    It’s called “Fabergé” not “Fabergè”.

  • ansis m Avatar

    This comment has been hidden.

  • lizeyujiayou Avatar

    The Description is too bad! I can't understand what it mean……

  • SlavenDj Avatar

    I have no idea how to get 105 out of 2 eggs and 14 tries. Is it allowed to give some explanation?

  • rdkbrady Avatar

    Question says: target floor can be any floor between 1 to this maximum height? Some of the answers are '0'

    This doesn't make any sense. For the case where you have no eggs, the max height should be 1. Either that or the target floor should be any floor between 0 and the max height.

  • azeer Avatar

    its too vague, could you please add another example (below 7 eggs 20 tries) i get 105 for 14 tries 2 eggs but for 7 eggs and 20 tries, i get a little more than 137979, i tested some cases and it seems to work. could it be that 137979 is not the actual maximum? maybe the boundaries(where an egg, each try is supposed to be dropped from) werent counted?

  • jharvey Avatar

    I'm having issues trying to understand this problem in C#. We have a infinite number of floors, m eggs and n trys. Previous comments suggest that 1 try = 1 egg. Since, there is no data on how to determine whether or not a egg breaks. We need to determine the maximum section we can clear accurately incase the egg does break.

    For example, the data suggests that 7 eggs with 20 tries = 137979 floors???

    However, if you have 7 eggs the maximum amount of floors you can test & have a accurate number is 70...70 x 20 = 1,400 < 137,979

    EXAMPLE: Say you are coming up from floor 70 and throw the egg at floor 140 (70 floors), it cracks...so you go half way floor 105, it cracks...so you go half way...you do this until you have 1 egg left which would mean that etheir it cracks on 71 and floor 70 is your highest or floor 71 is your highest floor.

    20 tries, clearing 70 floors each time, egg never breaks, = 1,400 floors

    So, now that I have presented my thought process, my question are as follows.

    1. How exactly are you guys determining whether or not the egg breaks? At the moment I can only assume that somehow 84 people who solved this came up with the same arbitrary numbers which is impossible.

    2. How are you getting numbers like 137,979 and still be accurate, to the exact floor?

    I am aware that I am probably thinking about the solution incorrectly. However, with the information presented I do not see how this is solvable under these conditions. The skyscaper is endless and we have no way of determining the egg breaking.

  • Danchieke Avatar

    Another question in the same vein as some below: running this in C#, getting correct answers, but the full test suite times out. For n=20000, m=30000 (above the test limit), this still only takes 808ms. How much faster does it need to be? Edit: down to 640ms, still no luck.

  • zakamarek Avatar

    I'm afraid there is something bad with your golang runtime env. When I ran my code locally (e.g. Height(311, 10131) ) it calculated the proper result 71692....6927, but in codewars environment the same code gave 0.

  • revliscano Avatar

    I have a solution in Python that in the worst case (n = 20000 and m = 20000) it takes 1.08s (measured with timeit). Still can't beat the timeout error. Can someone tell me at least how far am I to an acceptable solution (in time)??? How fast should I be aiming on this?

  • hodgesb Avatar

    This comment has been hidden.

  • PLAT1N Avatar

    This comment has been hidden.

  • JasonGoemaat Avatar

    This comment has been hidden.

  • aaronallen8455 Avatar

    Haskell version is broken - there's a case where n=99999 (n is supposed to be 20000 max).

  • pascal the wise Avatar

    SCALA VERSION got this error when attempting to push my solution:

    fixture.scala:33: warning: method + in class Int is deprecated (since 2.13.0): Adding a number and a String is deprecated. Use the string interpolation s"$num$str" FabergeTest.test(random.nextInt(20000) + "", random.nextInt(20000) + "") ^ fixture.scala:33: warning: method + in class Int is deprecated (since 2.13.0): Adding a number and a String is deprecated. Use the string interpolation s"$num$str" FabergeTest.test(random.nextInt(20000) + "", random.nextInt(20000) + "")

  • takahiroBro Avatar

    How are you suppose to do this without Excution Timeout. How efficient could it get? Does the algorithem need to be linear ? My approach can calculate (477,10000) but if there is more than one test trials with input integar larger than 10000, it causes timeout.

    Rip Kobe.

  • lecleremi Avatar

    This situation is unrealistic. Even with the fastest elevator in the world, there is no way you'll manage to go 10 to the power 3000 (which is roughly the answer to height(4477,10000)...) floors up multiple times so that you can re-use unbroken eggs. (Even just once actually...)

  • DoragonSoruja Avatar

    Is this a part two to another kata? Because I'm very confused as to why there is little to no information to work with.

  • fgm Avatar

    There is something unclear in the problem description. It says the eggs are almost identical (emphasis added), meaning they are not identical, so tries with one egg would not apply to another one: any series of try with one egg is independent from the series with another egg. Is this actually what is meant here ? In the issues thread, someone claims to assume they are actually identically behaving.

  • ernara Avatar

    This comment has been hidden.

  • shoq Avatar

    I don't think it's very realistic. If you drop an egg it surely gets some microtrauma even if it doesn't crack, making it more susceptible to crack in another throw.

  • lucky.joker.993@gmail.com Avatar

    This comment has been hidden.

  • Gealber Avatar

    Somebody can tell me if this problem is related with any situation in practice life. I haven't solve it yet, maybe that's why I don't see the point with this problem.

  • midwayfair Avatar

    This comment has been hidden.

  • zepher2211 Avatar

    I really don't understand where to start with this, given the . number of eggs and tries, how can I possibly know the height of the floors?

  • MDabrowski1990 Avatar

    This comment has been hidden.

  • BoeingX Avatar

    Hi, for the Haskell version, there is a typo in the function name: heigth should be height

  • houdeanie Avatar

    Hi, how does one store such high values in Python?

  • imranakhter57 Avatar

    how should I know when egg cracks, this isnt explained in the question?

  • monadius Avatar

    Idris:

    • Incorrect function name: heigth instead of height.

    • export should be added to specSuite in Sample Tests.

  • SahandJ Avatar

    I'm having troubles understanding this kata.

    All we get is N eggs, and max M tries. How am I supposed to know when do I know that an egg cracks?

    Am I completely misunderstanding it?

  • MANHAR Avatar

    The question was more about maths. I had a hard time figuring it though.

  • kodanv Avatar

    After completing the kata, I believe it's more about math. Although, it's inspiring to see nice pythonistic solutions

  • danieldsutter Avatar

    This comment has been hidden.

  • danieldsutter Avatar

    Does m = total tries or tries per egg?

  • robbertwethmar Avatar

    Its mostly a math problem I think. I had some problems getting the Javascript version to work, as the BigNumber documentation mentioned 'multipliedBy', while only 'times' and 'mul' work??? Maybe add some more documentation to reflect the working methods on BigNumber

  • VadKozJr Avatar

    Time: 1361ms Passed: 7 Failed: 0 Exit Code: 1 I have increased recursion depth and passed all cases with nice time, but still see exit code! How to solve this problem?

  • yury20 Avatar

    I think there is an issue with java solution. I have optimized all what are possible. I tryed two way of algorithm - from start and from end. But there is "Execution Timed Out (16000 ms)" I found another solution of this Kata in the Git and it also have the timeout error. Can anyone test your java-solution? Is it problem of this site or my problem?

  • MatthijsBlom Avatar

    This comment has been hidden.

  • Torkel Avatar

    This comment has been hidden.

  • gopheratl Avatar

    This comment has been hidden.

  • ivitojv Avatar

    This comment has been hidden.

  • g82918 Avatar

    Right now on the python version I am passing 36 tests and failing 24. All the failing tests are the randomly generated ones. Like:

    1498152621787493509656129759259203897865598852423L should equal 5846006549323611672814739330865132078623730171903L.

    Could someone give me some random test cases that would result in numbers like that so I can find my issue? I seem to somewhat consistently be off by a factor of 3.9 for these, but I pass the regular tests just fine.

  • COLONELBIHI Avatar

    when you say "when the target floor can be any floor between 1 to this maximum height?", does it mean that eggs never crack when falling from the first floor ?

  • Ziphwy Avatar

    Hello! I have written two solution which make with DP and combinations in javascript, but it can't pass the serious test: '4477,10000', '9477,10000'.

    And I found that the serious case is removed in Java.

    Would you like to help me?

  • akarmes Avatar

    Description is unclear. What's the function to throw an egg? As I understand, it takes a integer (height) and returns boolean (if egg got broken).

  • cscscscscscscs Avatar

    I have a problem with the explanation on tries: Can you throw multiple eggs at once per try? In the example of 2;14, in the first try, can I throw my eggs at the same time or its only ONE egg per try? So if I have 10 eggs and 10 tries, will I get 100 drops (10 per try) OR 10 egg drops (one per try)?

  • dwat3r Avatar

    This comment has been hidden.

  • kontic Avatar

    Great kata. I'll try to create better solution than this which I posted. Thanks.

  • KernelPryanic Avatar

    Hello! I'm new here, maybe don't know something, but there is no possibility to create 20000 x 20000 big.Int array in Go. Could you please reduce it to 10000 x 10000?

  • Ivana Avatar

    For all, who writes, that description is too unclear. Maybe you know, there is a good tradition in russian (and I think, it isnt much depends from the country) olimpiadic programming - put a task description in a such joke and unclear manner. Try out any contest/task and you will see it :) In that case, to understand a formal task is a part of whole task. Anywhere, this cata has been solved by 57 users, and I think they have understanded what are they have to do. So, I guess, it will be not good idea to explain all formal description in details. Thow, you may post issues and minuses, but I think so.

  • Voile Avatar

    This comment has been hidden.

  • VictorVazquezRey Avatar

    This comment has been hidden.

  • ok...ok...ok Avatar

    I don't understand if I can throw n eggs at every try or not. So let's suppose I throw 2 eggs and just one cracks, next try I have 2 eggs again or just one remains?

  • ThomFabian Avatar

    This comment has been hidden.

  • Thorwing Avatar

    I have no idea what is requested in this Kata. The description is unclear.

  • Ivana Avatar

    O, it is nice to see, that this my cata is wide-discussed and translated on many other languidges! I only hope, that my other catas (not only 2, that are approoved) will be such popular or ever be solved by anybody in near future - try they, they are interesting too :)

  • lolisa Avatar

    This comment has been hidden.

  • Schwarzwald Avatar

    I think the label "DYNAMIC PROGRAMMING" is improper. I can't make it with DP.

    In fact I think it is more like a math problem.

    I don't know whether the reason is that I use python so I can't make it with DP.

  • andbr Avatar

    I threw the egg 1000000 meters up on first try and it didn´t crack. Whats the logic behind this?

  • ReganRyanNZ Avatar

    This comment has been hidden.

  • cesare63 Avatar

    This comment has been hidden.

  • nomennescio Avatar

    I'm also baffled by the unclear description; what for instance is the definition of a 'try'? What does it mean to throw multiple eggs during one 'try'? I don't have a problem if your English is bad, but use a more formal description in that case.

  • imatmati Avatar

    Hi,

    I'd really like to train with this kata, but I must admit I don't understand the basic of it. How am I supposed to evaluate that an egg cracked ?

  • ice1000 Avatar

    Go translation added.

  • ice1000 Avatar
  • ice1000 Avatar
  • Voile Avatar

    This comment has been hidden.

  • ice1000 Avatar

    Typo fixed, Description modified, it's time to approve.

  • haugk Avatar

    Would someone approve my Ruby translation please or indicate what needs changing?

  • eod Avatar

    This kata's description is terrible! Please fix it.

  • haugk Avatar

    Haskell

    I enjoyed that kata. I like how many times I thought I had cracked it, only to be told that my solution was still not fast enough. I would have stopped optimising long before the final solution, had it not been for the limited execution time. It's amazing that you can always squeeze out more performant code when you have to.

  • bkaes Avatar

    Irritating typo in the function name: heigth should be height.

  • nickie Avatar

    Fix the typo in the function's name! (in Haskell)

  • Bodigrim Avatar

    an exactly maximal floor Maybe minimal floor?

    will crach typo: crack

    Ask a native speaker to proofread your text - there are grammar mistakes.

    I'd recommend to give a formal description of the problem after your informal introduction, which is not very clear.

  • mortonfox Avatar

    Wow! Quite a challenging kata. I must have tried at least a half dozen approaches before I found a way to compute it that was fast enough. Well done!

  • Ivana Avatar

    Why I can not submit final my solution, which passed all tests?

    UPD after 40 minutes I submit my solution - I think it was a site bag...