An industrial robotics fail-safe system monitors sensor data from two independent channels, representing 4×4 4 \times 4\,4×4 grids of signal levels. Each cell in a grid stores an integer value from 0 to 9.
Two grids are considered mutually stable if:
For example, Sensor B is mutually stable with Sensor A, but Sensor C is not:
| Col 0 | Col 1 | Col 2 | Col 3 | |
|---|---|---|---|---|
| Row 0 | 2 | 7 | 5 | 1 |
| Row 1 | 3 | 4 | 8 | 6 |
| Row 2 | 0 | 9 | 2 | 4 |
| Row 3 | 6 | 1 | 5 | 3 |
| Col 0 | Col 1 | Col 2 | Col 3 | |
|---|---|---|---|---|
| Row 0 | 7 | 2 | 4 | 8 |
| Row 1 | 6 | 5 | 1 | 3 |
| Row 2 | 9 | 0 | 7 | 5 |
| Row 3 | 3 | 8 | 4 | 6 |
| Col 0 | Col 1 | Col 2 | Col 3 | |
|---|---|---|---|---|
| Row 0 | 7 | 2 | 4 | 8 |
| Row 1 | 6 | 5 | 2 | 3 |
| Row 2 | 9 | 0 | 7 | 5 |
| Row 3 | 3 | 8 | 4 | 6 |
(Note: In Sensor C, Row 1, Col 2 has a value of 2, while in Sensor A, Row 1, Col 2 has a value of 8. Their sum is 10, not 9.)
A systems engineer has drafted a pseudo-code algorithm to check if two 4×4 4 \times 4\,4×4 sensor grids, sensorA and sensorB, are mutually stable.
Complete the algorithm in pseudo-code, ensuring that, when the algorithm terminates, the variable isStable is set to true if they are mutually stable, or false otherwise.
The algorithm must work for any valid 4×4 4 \times 4\,4×4 grids stored in sensorA and sensorB. Zero-based indexing is used.
sensorA ← [ [2, 7, 5, 1], [3, 4, 8, 6], [0, 9, 2, 4], [6, 1, 5, 3] ]
sensorB ← [ [7, 2, 4, 8], [6, 5, 1, 3], [9, 0, 7, 5], [3, 8, 4, 6] ]
isStable ← true
r ← 0
WHILE r ≤ 3
c ← 0
WHILE c ≤ 3
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.