An automated municipal lighting system controls a street with 7 smart lamps, indexed 0 to 6.
The subroutines in the table below are used to manage the states of the lamps, switching them between ON and OFF.
| Subroutine | Explanation |
|---|---|
INVERT(n) | If the lamp at index n n\,n is ON it is set to OFF. If it is OFF it is set to ON. |
MIRROR(n) | The lamp at index n n\,n is set to the same state as the lamp at index n+1n + 1n+1. |
EXTINGUISH_BETWEEN(m, n) | All lamps strictly between index m m\,m and index nnn (but not including m m\,m and nnn) are set to OFF. |
If the starting array of lamps is:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| ON | ON | ON | ON | ON | ON | ON |
Write an algorithm, using exactly three subroutine calls, that means the final array of lamps will be:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| OFF | OFF | OFF | OFF | OFF | OFF | OFF |
You must use each of the subroutines INVERT, MIRROR and EXTINGUISH_BETWEEN exactly once in your answer.
208 exam-style questions on AQA GCSE Computer Science Representing algorithms. Each one has a worked solution and a mark scheme showing where the marks go.