0

Please I need some help on this question I don't know how to create a calculation for the distance and when to break it .

The snail climbs up 7 feet each day and slips back 2 feet each night. How many days will it take the snail to get out of a well with the given depth? Sample Input: 31 Sample Output: 6 Explanation: Let's break down the distance the snail covers each day: Day 1: 7-2=5 Day 2: 5+7-2=10 Day 3: 10+7-2=15 Day 4: 15+7-2=20 Day 5: 20+7-2=25 Day 6: 25+7=32 So, on Day 6 the snail will reach 32 feet and get out of the well at day, without slipping back that night.

14th Aug 2021, 10:47 AM
Obinna Anosike
Obinna Anosike - avatar
4 Answers
+ 2
a = first term d = common difference n = term an = distance covered by snail on a particular day. formula: a + (n - 1)d = an
14th Aug 2021, 10:58 AM
Rellot's screwdriver
Rellot's screwdriver - avatar
+ 2
Obinna Anosike First observe that every time we reach a new distance, we reach it with the 7-step, so there are always one more 7-step than 2-steps. After n days we reach distance d: 7*n - 2*(n-1) = d <=> 7*n - 2*n + 2 = d <=> 5*n = d - 2 => n = ceil((d-2)/5) Lets plug 32 in: n = ceil((32-2)/5) = ceil(30/5) = 6 days
14th Aug 2021, 1:32 PM
Giorgos
0
I don't understand please explain
14th Aug 2021, 11:07 AM
Obinna Anosike
Obinna Anosike - avatar
0
Is n the unknown to find which is the days
14th Aug 2021, 11:08 AM
Obinna Anosike
Obinna Anosike - avatar