DEV Community

dev.to staff
dev.to staff

Posted on

Daily Challenge #96 - Easter Egg Crush Test

Eulampy has a collection of some almost identical Fabergè eggs. One day his friend Tempter said to him:

  • Do you see that skyscraper? And can you tell me a maximal floor that if you drop your egg from will not crack it?
  • No, - said Eulampy.
  • But if you give me N eggs, - says Tempter - I'll tell you an answer.
  • Deal - said Eulampy. But I have one requirement before we start this: if I will see more than M falls of egg, my heart will be crushed instead of egg. So you have only M tries to throw eggs. Would you tell me an exact floor with this limitation?

Your task is to help Tempter - write a function

height :: Integer -> Integer -> Integer
height n m = -- see text

that takes 2 arguments - the number of eggs n and the number of trys m - you should calculate maximum skyscraper height (in floors), in which it is guaranteed to find an exactly maximal floor from which that an egg won't crack it.

Which means,

  • You can throw an egg from a specific floor every try

  • Every egg has the same, certain durability - if they're thrown from a certain floor or below, they won't crack. Otherwise, they crack.

  • You have n eggs and m tries

What is the maximum height, such that you can always determine which floor the target floor is when the target floor can be any floor between 1 to this maximum height?

Examples
height 0 14 = 0
height 2 0 = 0
height 2 14 = 105
height 7 20 = 137979

Data range
n <= 20000
m <= 20000


This challenge comes from Ivana on CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!

Top comments (6)

Collapse
 
qm3ster profile image
Mihail Malo • Edited

I don't understand, what is the difference between a try and an egg?

Seems to me like it's

const height = (n, m) => 2 ** Math.min(n, m)

I don't understand how the example results were produced.

Collapse
 
aminnairi profile image
Amin

You can't make mayonnaise out of a try. But you can try to make mayonnaise out of an egg (don't forget the oil and the mustard though).

Collapse
 
qm3ster profile image
Mihail Malo

Jesus Christ

Collapse
 
qm3ster profile image
Mihail Malo • Edited

Maybe because 🅱️inary search is 🅱️rogramming? 🤷

Edit: 🅱️ 🅱️ 🅱️ 🅱️

Collapse
 
peledzohar profile image
Zohar Peled

I was once asked a similar question in an interview. I didn't know it back then and I can't remember it now..