Skip to content

Course home

Representing algorithms

Representing algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
Question 58

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.

SubroutineExplanation
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:

0123456
ONONONONONONON

Write an algorithm, using exactly three subroutine calls, that means the final array of lamps will be:

0123456
OFFOFFOFFOFFOFFOFFOFF

You must use each of the subroutines INVERT, MIRROR and EXTINGUISH_BETWEEN exactly once in your answer.

[3]
Markscheme

Representing algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Representing algorithms

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.

Question bank