AQA GCSE Computer Science June 2024 Paper 1, Questions 12.1 to 12.5: reading the sliding puzzle

AQA 8525 June 2024 Paper 1, Questions 12.1 to 12.5: work out where the tiles end up after two conditional moves, then read a pair of nested for loops that scan a 3 by 3 board for the blank space. Every board drawn out, with the puzzle to run.

Past paper questionAQA 8525/1BJune 2024 Paper 17 marksRead the code

Questions 12.1 to 12.5 of the AQA GCSE Computer Science Paper 1 sat on 15 May 2024 (8525/1B, the Python paper) are the reading half of the long sliding puzzle question: 7 marks for following two short programs against boards drawn on the paper. The two programs you write, 12.6 and 12.7, are on their own page.

We do not copy the exam paper here. Open it beside this page: AQA June 2024 Paper 1B question paper (PDF). When you have finished, check the mark scheme too.

The puzzle

A 3 by 3 board holds tiles 1 to 8 and one blank, which the program stores as 0. Positions are given as (row, column), both counted from 0. getTile(row, column) returns the tile there. move(row, column) slides that tile into the blank, but only if the blank is next to it. displayBoard() shows the board.

12.1: run the two moves (2 marks)

The board on the paper has the blank at (1, 0), with 4 below it at (2, 0) and 2 at (2, 1). The program is:

  • if the tile at (1, 0) is 0, move (2, 0);
  • if the tile at (2, 0) is 0, move (2, 1);
  • display the board.

Work through it in order, updating the board after each move.

  1. Is (1, 0) the blank? Yes. So tile 4 slides up from (2, 0) into (1, 0). The blank is now at (2, 0).
  2. Is (2, 0) the blank? Yes, because the first move just put it there. So tile 2 slides left from (2, 1) into (2, 0). The blank is now at (2, 1).

The finished board: row 0 unchanged, row 1 has 4 where the blank was, row 2 has 2 on the left and the blank in the middle. One mark for 4 in its new place, one for 2 in its.

The point of the question is the second if. It looks at the board after the first move, not the board on the paper.

12.2 to 12.5: the scan for the blank

The second program is two nested loops: for i in range(3), then for j in range(3), then if getTile(i, j) == 0, store i in ref1 and j in ref2. On the paper's board the blank is at (2, 0).

12.2, two true statements: nested iteration is used (A), and nine comparisons are made (C). The loops look at every square whatever the board, so it is always nine. The outer loop runs three times, not nine (D is false). ref1 ends as 2, not 0 (B is false). i and j change on every pass (E is false).

12.3: the first loop goes through the rows.

12.4: the second loop goes through the columns. (The mark scheme gives both marks if you say columns then rows, as long as they are the opposite way round.)

12.5: the program finds the position of the blank space and stores it in ref1 and ref2.

Where the marks are lost

  • Using the original board for both moves. After the first move (2, 0) is the blank, so the second if is true.
  • Three comparisons. Nine squares, nine calls to getTile. There is no break.
  • "The loop counts to 3" for 12.3. Say what it is for: going along each row.
  • "It checks the tiles" for 12.5. It looks for one particular thing, the 0, and records where it is.

Run it

The board from 12.1, the two moves, and then the scan from 12.2, which prints every comparison it makes. The robot's light goes green when the blank is found.

After the moves the board is 1 8 3, 4 7 5, 2 _ 6. The scan makes nine comparisons and finds the blank at row 2, column 1.
The program
from bugbot import *
connect()

board = [[1, 8, 3], [0, 7, 5], [4, 2, 6]]

def getTile(row, column):
    return board[row][column]

def blank():
    for r in range(3):
        for c in range(3):
            if board[r][c] == 0:
                return r, c

def move(row, column):
    r, c = blank()
    if abs(r - row) + abs(c - column) == 1:
        board[r][c] = board[row][column]
        board[row][column] = 0

def displayBoard():
    for line in board:
        print(line)

# 12.1
if getTile(1, 0) == 0:
    move(2, 0)
if getTile(2, 0) == 0:
    move(2, 1)
displayBoard()

# 12.2 to 12.5
comparisons = 0
for i in range(3):
    for j in range(3):
        comparisons = comparisons + 1
        if getTile(i, j) == 0:
            ref1 = i
            ref2 = j
print(comparisons, "comparisons; the blank is at row", ref1, "column", ref2)
led("green")
Put this demo on your own site

Paste it into a school website, Moodle, Google Sites or a blog. More options on the embed page.

Questions

What is the answer to AQA GCSE Computer Science 2024 Paper 1 Question 12.1?

Tile 4 moves up into row 1, column 0, and then tile 2 moves left into row 2, column 0. The blank ends at row 2, column 1.

What is the answer to Question 12.2?

A and C: nested iteration is used, and nine comparisons are made between getTile(i, j) and 0.

What do nested for loops over range(3) do on a 3 by 3 board?

The outer loop picks each row in turn and the inner loop picks each column, so together they visit all nine squares, one at a time, in reading order.

More from this paper

Every AQA 8525 question we have worked

Learn it step by step

  1. F3.5 Two-dimensional arrays Strings, lists and records
  2. F4.2 Parameters and return values Functions and structured code
Open the lessons

This is our own explanation of a published exam question. It is not written or endorsed by AQA, and the question paper and mark scheme remain AQA's copyright. Read them on AQA's site with the links on this page.