In the English fairy tale, Jack and the beanstalk, Jack is a young, poor boy living with his mother and a dairy cow on a farm cottage. The cow’s milk is their only source of income. When the cow stops giving milk, Jack’s mother tells him to take her to the market to be sold. On the way, Jack meets a curious man who offers magic beans in exchange for the cow, and surprisingly Jack makes the trade. When he arrives home without any money, his mother becomes angry, throws the beans out of the window, and sends Jack to bed without dinner.
During the night, the magic beans cause a gigantic beanstalk to grow outside Jack’s window. Let’s stop the fairy tale story here and focus on the magic beanstalk.
By studying its growth we found out the beanstalk was 100cm high just one hour after Jack’s mother sent the bean out of the window. After that the beanstalk grew at the following rate:
So we can plot the following growth table and chart:
|Hours||Height Calculation||Beanstalk Height (in cm)|
|2||100 x 1.5 + 30||180|
|3||180 x 1.5 + 30||300|
|4||300 x 1.5 + 30||480|
|5||480 x 1.5 + 30||750|
|6||750 x 1.5 + 30||1155|
Using this information, can you work out the height of the magic beanstalk after 7 hours?
The next morning, the beanstalk was so high it could reach the sky! Can you work out the height of the beanstalk after 12 hours?
Using an algorithm…
To calculate the height of the beanstalk at any given time/hour we have decided to use an algorithm as follows:
Your task is to implement this algorithm using Python and calculate the height of the beanstalk after 12 hours or after a full day (24 hours).
Solution...The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area