This problem is part of our Ada Lovelace Day celebration. It is for practice only and will NOT count towards your grade!
(just have fun and use it to improve your skills: there is no submission deadline!)


In this problem you should submit a function as described. Inside the function do not print anything that was not asked!

The name of the .py source file you submit to Mooshak should NOT start with a digit (you will get an error if you submit it like that).

[ALD06] Mary’s Wind Tunnel

Mary Jackson was an American mathematician and aerospace engineer.

She began her career at NACA, NASA’s predecessor, as a human computer, performing mathematical calculations before electronic computers were common.

In 1958, she became NASA’s first Black female engineer!

Her work included wind-tunnel experiments that helped scientists study how air flows around aircraft.

Can you help Mary simulate a simple wind-tunnel test?

The Problem

Implement the function wind_tunnel(start_speed, target_speed, amount).

The function receives three integer parameters:

The function must return an integer representing the number of steps needed to reach (or exceed) the target, or -1 if the target cannot be reached.

The simulation follows these rules:

If the target speed is reached on the same step that reduces the next amount to zero, the result is still successful and should count as a step in the simulation.

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

0 ≤ start_speed ≤ 109       initial air speed
0 ≤ target_speed ≤ 109       target air speed
0 ≤ amount ≤ 109       first speed increase

Example Function Calls 1 Example Output 1
print(wind_tunnel(20, 50, 16))

4

For the call above, the simulation starts with start_speed=20.
The initial amount is amount=16 and the target_speed=50 :

Step Increase applied Speed after the step
Start — 20
1 16 36
2 8 44
3 4 48
4 2 50

The target is reached after four steps, so the function returns 4.

Example Function Calls 2 Example Output 2
print(wind_tunnel(20, 60, 16))
-1

In this second call, the applied increases are 16, 8, 4, 2, 1.
The speed reaches 51, after which the increase becomes zero.
Because 51 is below 60 (and the increase amount will never be different than 0) the function returns -1.

Step Increase applied Speed after the step
Start — 20
1 16 36
2 8 44
3 4 48
4 2 50
5 1 51
6 0 51

Example Function Calls 3 Example Output 3
print(wind_tunnel(20, 30, 16))
1

In this third call, the first step reaches 36, exceeding the target of 30, so the result is 1.

Step Increase applied Speed after the step
Start — 20
1 16 36


Example Function Calls Example Output
print(wind_tunnel(50, 50, 16))
print(wind_tunnel(60, 50, 0))
print(wind_tunnel(20, 50, 0))
print(wind_tunnel(0, 11, 7))
print(wind_tunnel(0, 12, 7))
print(wind_tunnel(0, 1, 1))
0
0
-1
3
-1
1

Introduction to Programming (CC1024)
DCC/FCUP - University of Porto