NYJC 2025 H2 Computing Prelim Paper 2
Uploaded by Kozak327 · 25 August 2026
Preview
Text from the first pagesThis document consists of 8 printed pages and 1 insert. © NYJC 2025 [Turn over NANYANG JUNIOR COLLEGE JC2 PRELIMINARY EXAMINATIONS Higher 2 COMPUTING 9569/02 Paper 2 (Lab-based) 28th August 2025 3 Hours Additional Materials: Removable storage device Electronic version of Route.csv data file Electronic version of Service.csv data file Electronic version of Stop.csv data file Electronic version of ARTEFACTS.txt data file Insert Quick Reference Guide READ THESE INSTRUCTIONS FIRST Answer all questions. All tasks must be done in the computer laboratory. You are not allowed to bring in or take out any pieces of work or materials on paper or electronic media or in any other form. Approved calculators are allowed. Save each task as it is completed. The use of built-in functions, where appropriate, is allowed for this paper unless stated otherwise. Note that up to 6 marks out of 100 will be awarded for the use of common coding standards for programming style. The number of marks is given in brackets [ ] at the end of each question or part question. The total number of marks for this paper is 100.
2 9569/02/2025 Instruction to candidates: Your program code and output for each of Task 1, 2 and 3 should be downloaded in a single .ipynb file. For example, your program code and output for Task 1 should be downloaded as TASK1_<your name>_<centre number>_<index number>.ipynb Make sure that each of your .ipynb files shows the required output in Jupyter Notebook. 1 Name your Jupyter Notebook as: TASK1_<your name>_<centre number>_<index number>.ipynb A number-sliding game consists of a 3-by-3 game board and 8 number tiles, as shown below: There is one blank on the board, into which an adjacent tile can be slid horizontally or vertically. The coordinates of the game board comprise two integers ( x, y), with y representing the row index and x representing the column index. Row indices increase downwards, while column indices increase rightwards. In the above board, the number 1 has coordinates (0, 0), the number 2 has coordinates (1, 0), the number 4 has coordinates (0, 1), and so on. The board is represented by a Board class that encapsulates game data. For each of the sub -tasks, add a comment statement, at the beginning of the code using the hash symbol ‘#’, to indicate the sub-task the program code belongs to, for example: In [1]: # Task 1.1 Program code Output: Task 1.1 Write program code to declare the class Board. Each Board stores the following information: ● data – a 9-item array containing the numbers in the board. The blank tile is represented by the number 0. ● blank – the coordinates of the blank. The class Board should be initialised without any arguments and should contain initialised board data identical to the above diagram. It should have the following methods: ● get(x, y) returns the number at coordinate (x, y). Coordinates can be converted into an array index i using the formula i = y * w + x, where w is the width of the board. ● set(x, y, n) stores the number n at coordinate (x, y). [5] 1 2 3 4 5 6 7 8
3 9569/02/2025 [Turn over Task 1.2 The SlidingGame class inherits from Board, and implements the following methods: ● is_valid(x, y) returns True if (x, y) is a valid coordinate and the tile at (x, y) can slide into the blank, otherwise it returns False. A tile can slide if it is horizontally or vertically adjacent to the blank. (An array index can be converted into coordinates using y = i // w and x = i % w, where w is the width of the board.) ● slide(x, y) slides the tile at coordinate (x, y) into the blank, and returns True. After this is successfully done, the blank should now be at coordinate (x, y). If this is not valid or possible, then False should be returned instead. ● options() returns a list of (x, y) coordinates representing tiles that can slide. ● is_complete() returns True if the board is complete, otherwise it returns False. A board is complete if: ○ the blank is at the end of the array, and ○ the array (except for the last tile) is sorted in ascending order. • display() displays the board contents as a 3-by-3 grid. Write program code to declare the class SlidingGame. [10] Test your code by instantiating the SlidingGame class. [1] Task 1.3 The number-sliding game can be shuffled into a starting state, starting from a complete board, by: 1. checking for valid options, 2. picking a random move from step 1 and executing it, 3. repeating steps 1 and 2 until the first array value is no longer 1. Write a function shuffle_game(game) that: • takes in a SlidingGame instance, • carries out the above algorithm to shuffle the board. [4] Run your program, displaying the state of the board before and after the shuffle. [2] Task 1.4 Write program code to implement a number-sliding game which: 1. displays the board 2. prompts the player to pick from valid tiles to slide 3. slides the tile, or re-prompts the player if their input is invalid 4. ends the game when the board is complete, and show s the player the number of moves used 5. otherwise, repeats from step 1. [5] Save your Jupyter Notebook for Task 1.
4 9569/02/2025 2 Name your Jupyter Notebook as: TASK2_<your name>_<centre number>_<index number>.ipynb A museum maintains information about its artefacts in the following format: [(artefactID,rating),…] where: • artefactID is a single uppercase letter followed by 4 digits (e.g., A1234, B5678) • rating is an integer between 1 and 100 representing the historical significance The museum’s artefacts are provided in ARTEFACTS.txt and may be copied from the file to be used in your code. The data format provided in ARTEFACTS.txt is as follows: [(A1234,85),(B1234,85),(C1234,85),…] For each of the sub -tasks, add a comment statement at the beginning of the code using the hash symbol '#', to indicate the sub-task the program code belongs to, for example: In [1]: # Task 2.1 Program code Output: Task 2.1 Write a function task2_1(artefacts_list) that: • takes a list of tuples artefacts_list • validates that each artefactID starts with an uppercase letter followed by a 4-digit number between 1000-9999 inclusive, outputting an appropriate error message if data is invalid • validates that each rating is between 1 and 100 inclusive, outputting an appropriate error message if data is invalid • returns a list of tuples containing valid (artefactID, rating) pairs. [4] Test your function with the artefacts list in ARTEFACTS.txt and output: • the total number of valid artefacts read • the first 5 artefacts in the list. [1] Task 2.2 Write a function task2_2(artefacts_list) that: • takes a list of artefactID-rating pairs as a parameter • implements a quicksort algorithm to sort the artefacts by rating in descending order • uses the first element as the pivot • returns the sorted list. [6] Test your function with the artefacts list in ARTEFACTS.txt. [1]
5 9569/02/2025 [Turn over Task 2.3 Write a procedure task2_3(artefacts_list, target_rating) that: • uses your function from Task 2.2 to sort the artefacts by rating in descending order • implements a binary search to find an artefact with target_rating • returns an (artefactID, rating) pair if found or None if not found. [8] Test your function with: • target_rating = 85 • target_rating = 100 Output an appropriate message for each test case. [2] Save your Jupyter notebook for Task 2.
6 9569/02/2025 3 Name your Jupyter Notebook as: TASK3_<your name>_<centre number>_<index number>.ipynb A game engine uses a circular queue for its particle effects renderer. The queue uses a statically allocated array for particles. Each particle has a colour, represented as an integer from 0 ‒ 255. A value of ‒1 represents a null value in a pointer. The program uses three global variables: • particles the array of particles • head the index of the first pa
Content continues in the PDF. Download PDF
Related notes
- JPJC 2024 JC2 Prelim Paper 2 QPExam Papers · 2024
- JPJC 2024 JC2 Prelim Paper 2 MS v2Exam Papers · 2024
- JPJC 2024 JC2 Year-End Exam H2 Computing Paper 1Exam Papers · 2024
- JPJC 2024 JC2 Year-End Exam H2 Computing Paper 1 Marking SchemeExam Papers · 2024
- 2024 ASR H2 Computing Prelim P1 SolExam Papers · 2024
- 2024 ASR H2 Computing Prelim P1 QnsExam Papers · 2024
- 2025 VJC H2 Computing Prelim Paper 1Exam Papers · 2025
- 2025 VJC H2 Computing Prelim Paper 1 SolutionsExam Papers · 2025
- 2025 TJC H2 Computing Prelim Paper 1 SolutionsExam Papers · 2025
- RVHS 2025 H2 Computing Prelim Paper 1Exam Papers · 2025
- RVHS 2025 H2 Computing Prelim Paper 1 SolutionsExam Papers · 2025
- RI 2025 H2 Computing Prelim Paper 1Exam Papers · 2025
- See all H2 Computing notes

