An automated facility security corridor controls a row of 7 heavy security gates, indexed 0 to 6.
The subroutines in the table below are used to control the state of the gates, switching them between locked and unlocked.
| Subroutine | Explanation |
|---|---|
FLIP(n) | If the gate at index n is locked it is set to unlocked. If it is unlocked it is set to locked. |
DUPLICATE(n) | If the gate at index (n - 1) is locked, the gate at index n is set to locked. If the gate at index (n - 1) is unlocked, the gate at index n is set to unlocked. |
RELEASE_BETWEEN(m, n) | All gates strictly between index m and index n (but not including m and n) are set to unlocked. |
If the starting array of gates is:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| locked | locked | locked | locked | locked | locked | locked |
Write an algorithm, using exactly three subroutine calls, that means the final array of gates will be:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| unlocked | unlocked | unlocked | unlocked | unlocked | unlocked | unlocked |
You must use each of the subroutines FLIP, DUPLICATE and RELEASE_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.