Gates

Consider a reservoir with a number of gates that can be open or closed. The number of gates to hove open at a given day depends on three factors:

  • the number of gates of the reservoir

  • the supply and demand of electricity for the previous week (in kWh)

  • the day of the week

When supply exceeds demand, only a quarter of the gates is open. Otherwise, the number of gates depends on a parameter called #b which is the integer number of 50 kWh blocks in the difference between offer and demand. For example, if the offer is 310 kWh and the demand is 650 kWh, then the difference would be 340 and #b would be 6 (if it was 350 then it would be 7).

Based on #b value, there are three situations that determine the gates to have open:

  • All gates are opened if #b equals or exceeds the total number of gates.

  • Only half of the gates are opened if #b values is between the total number of gates and half of that, both excluded.

  • Only a third of the gates are opened if #b is equal or lower than a half of the number of gates.

Independently of all that, if the day is Saturday or Sunday, the number of gates that are open is decremented by two.

Finally, there is a security norm by which at least one gate must always be open.

You are required to implement the following functions in the module gates_module (file gates_module.py):

The main function is

gates(n, sup, dem, day)

such that

given

  • n, a positive int with the total number of gates.

  • sup, dem, int values of the supply and the demand of the previous week (in kWh), respectively.

  • day, a 3-char str indicating the day of the week (‘mon’, ‘tue’, ‘wed’, ‘thu’, ‘fri’, ‘sat’, ‘sun’).

returns an int with the number of gates to have open according to the previous norms.

For example:


>>> gates(12, 100, 75, 'wed')
3
>>> gates(12, 100, 180, 'tue')
4
>>> gates(12, 100, 180, 'sat')
2
>>> gates(5, 100, 480, 'mon')
5
>>> gates(6, 200, 480, 'mon')
3
>>> gates(6, 200, 220, 'sun')
1

Doctests are available in the gates.test file.