ExamBank Scot · AH Computing Science question bank · All AH Computing Science questions

AH Computing Science 2024 Question 3

2 marks · 2-D arrays

Using a programming language of your choice, define a 2-D array structure that can be used to store the puzzle data in a program. The highlighted mini-grid in the middle of the puzzle contains the value 9. Using a programming language of your choice, write the code that would assign this value to the appropriate element of the array that you defined part (a). The Sudoku puzzle is played on a grid as shown below. Each row, column and cell in the grid must be filled using the numbers 1 to 9, without repeating any numbers within the row, column or mini-grid. A completed Sudoku puzzle is shown below. 8 3 1 9 4 2 4 9 8 1 5 6 3 7 6 8 3 2 7 9 5 1 4 7 5 1 3 4 6 2 8 9 2 5 7 9 3 4 6 1 7 6 1 2 4 9 5 8 9 4 5 6 8 7 2 3 6 2 4 8 1 3 7 5 3 8 6 5 7 1 9 2 5 1 7 9 3 2 8 4 6

Marking scheme

DECLARE grid AS ARRAY OF ARRAY OF INTEGER [ ] <9 x 9 array, all set to zero> OR DECLARE grid TO [ [] ] * 9 FOR count FROM 0 TO 8 DO SET grid [count] TO [0] * 9 END FOR 1 mark for definition of 2D array of integer values with dimensions 9 × 9. Also accept solutions in other programming languages eg DIM grid (8,8) AS INTEGER SET grid[3,4] TO 9 Also accept: SET grid[4,3] TO 9 SET grid[4,5] TO 9 SET grid[5,4] TO 9

Previous question: AH Computing Science 2024 Question 2

Next question: AH Computing Science 2024 Question 4