Problem 42514. The Hills Are Alive...

After a long day of coding, you decide to get some fresh air and hike up a nearby hill. The hill isn't very tall, but since you spend so much of your spare time on Cody, you aren't used to climbing, and only make it a fraction of the way up the hill before setting up camp for the night. While you're asleep, something very strange happens: the hill grows by a certain amount. Fortunately, the hill's growth is proportional, so you are higher up the (now taller) hill than you were the previous day. Undaunted, you continue climbing up the hill, determined to reach the top.

Assuming you climb the same height each day, and that the hill grows by the same amount each night, write a MATLAB script that will tell you how many days it will take you to reach the top of the hill. The inputs will be the starting height of the hill, the amount it grows each night, and how high you can climb each day.

Example - The hill starts off at 200 meters tall, and you climb up 50 meters before setting up camp. At the end of day 1, you're 50 meters up a 200 meter hill. The hill grows 100 meters that night while you're asleep. At the start of the second day, you're now 75 meters up a 300 meter hill. You climb another 50 meters, putting you 150 meters up the hill. That night, the hill grows another 100 meters. This procedure continues until the 10th day, when you finally reach the summit of a now 1100 meter "hill."

Here, height=200, daily_growth=100, and climb=50. The output of your script should be d=10.

Solution Stats

59.46% Correct | 40.54% Incorrect
Last Solution submitted on Apr 01, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers11

Suggested Problems

More from this Author80

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!