computing 2026 asrjc prelim p2 qn
Uploaded by ChthonicCream · 17 October 2026
Preview
Text from the first pages[Turn over COMPUTING 9569/02 Paper 2 (Lab-based) 21 August 2026 (Friday) 8-11am 3 hours Additional Materials: Electronic version of MASTERMIND_GUESSES.txt datafile Electronic version of ANIMAL_DATA.json file Electronic version of GP_SCORES.txt data file Electronic version of ROOMS.txt data file Electronic version of STUDENTS.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. Do NOT write or make any markings on the Insert Quick Reference Guide. 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 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. This document consists of 15 printed pages and 1 blank page. Anderson Serangoon Junior College ANDERSON SERANGOON JUNIOR COLLEGE JC2 Preliminary Examination 2026 Higher 2
2 Instructions to candidates: Your program code and output for each of Task 1 to 4 should be saved in a single .ipynb file. For example, your program code and output for Task 1 should be saved as: TASK1_<your name>_<centre number>_<index number>.ipynb 1 Name your Jupyter Notebook as: TASK1_<your name>_<centre number>_<index number>.ipynb This task is based on Mastermind, a classic code -breaking game. One player (the code -maker) selects a secret sequence of 4 pegs, each coloured Red ( R), Yellow (Y), Green (G), or Blue ( B). Colours may repeat within the code. The other player (the code -breaker) makes a guess, also a sequence of 4 coloured pegs, and receives feedback in the form of two numbers: • Hits: the number of pegs that are the correct colour and in the correct position. • Pseudo-hits: the number of pegs that are the correct colour but in the wrong position. Each peg in the guess and each peg in the secret code can only be used once when scoring. A peg already counted as a hit cannot also count as a pseudo-hit (this matters when colours repeat). For instance, if the secret code is RGBY and the guess is GGRR: • Position 2 (with G) is a hit. • Of the remaining letters, only one R can be matched as a pseudo-hit. The result is thus 1 hit and 1 pseudo-hit. For each of the sub -tasks, add a comment statement at the beginning of the code using the symbol ‘#’, to indicate the sub-task the program code belongs to, for example: In [1]: #Task 1.1 Program code Output:
[Turn over Task 1.1 Write a function is_valid(code) that returns a boolean. The function should: • check that code is a string of exactly 4 characters, • check that every character in code is one of "R", "Y", "G" or "B", • return True if both conditions are met, and False otherwise. Test your function with the following statements: print(is_valid("RYGY")) print(is_valid("RGB")) print(is_valid("YYYY")) print(is_valid("BRGE")) print(is_valid("")) print(is_valid(["R","G","B","Y"])) print(is_valid(6767)) Show the output for each test. [4] Task 1.2 Write a function score_guess(secret, guess). It should first use the function in Task 1.1 to check that both secret and guess are valid; if either is invalid, return None. Otherwise, the function should: • count the number of hits, • count the number of pseudo-hits, and • return the result as a tuple (hits, pseudo_hits). Test your function with the following statements and show the output: print(score_guess("RGBY", "GGRR")) print(score_guess("RGGB", "RGGB")) print(score_guess("RGGB", "YYYY")) [5]
4 Task 1.3 (a) Write a function load_guesses(filename, secret)that: • reads a text file which contains eight past guesses, one on each line, • for each guess, calls score_guess() to calculate its hits and pseudo-hits, • calculates a value for each guess using: value = hits × 10 + pseudo_hits, • builds a tuple (slot1, slot2, slot3, slot4, value) for that guess, where slot1 to slot4 are the four individual characters of the guess. The function should return a list of these tuples. Call this function with the secret RGGB and the given text file MASTERMIND_GUESSES.txt. Output the returned list. (b) Write a function insertion_sort(guesses) that takes a list of tuples (in the form returned by load_guesses()) and sorts them in ascending order of value, using the insertion sort algorithm. Call this function using the list from part (a), store the result as sorted_data, and print sorted data. [6] Task 1.4 Write a recursive function binary_search(data, target) that searches a sorted list of tuples (in the form returned by load_guesses()) for a tuple whose value matches the given target. The function should return the matching tuple, or None if no matching tuple is found. If more than one tuple has the same value, returning any one of them is acceptable. Test your function by searching sorted_data for three different target values: 21 40 15 Output the result of each search. [5] Save your Jupyter Notebook for Task 1.
[Turn over 2 Name your Jupyter Notebook as: TASK2_<your name>_<centre number>_<index number>.ipynb PawsHaven Animal Shelter has been rescuing and rehoming dogs, cats and rabbits. The shelter’s management has asked you, as a newly recruited developer, to develop a system for their record -keeping. Your job is to load the shelter’s existing records into a NoSQL database so staff can query and update animal records. You are also to build a queue using a linked list to manage the intake line of animals currently waiting to be processed at the shelter. You have been given the shelter’s current records as a file ANIMAL_DATA.json. For each of the sub -tasks, add a comment statement at the beginning of the code using the 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 Python code that: • creates a MongoDB database paws_haven and a collection animals, • inserts all records from ANIMAL_DATA.json into the animals collection, • queries the collection to count the number of animals currently in shelter and the number of them who have left, • displays the output in the format: Animals currently in shelter: _________________ Animals who have left: _________________ [4] Task 2.2 Write two MongoDB queries to filter animals based on the following combinations of conditions. For each of them, output the number of matching animals, as well as these basic information for each matching record: animal_id, name, species.
6 Combination 1: All vaccinated cats that have left the shelter between 1 March 2025 and 31 January 2026 (both inclusive). Combination 2: All unvaccinated dogs and rabbits currently in the shelter with an adoption fee strictly greater than $45. [5] Task 2.3 Animals that are sent to the shelter need to be queued for the staff to process their intake (e.g. health check, paperwork, assigning a kennel). You will build this queue using a linked list, implemented as Node class and a Queue class. • The Node class should have two properties: o data: the value stored in the node, o next: a reference to the following node in the chain, or None if there isn't one. • The Queue class should maintain references to the front and back of the chain of nodes, along with a count of the number of items currently in the queue. It should support the following met
Content continues in the PDF. Download PDF
Related notes
- computing 2026 jpjc prelim p1 ansExam Papers · 2026
- computing 2026 hci prelim p2 qnExam Papers · 2026
- computing 2026 hci prelim p1 qnExam Papers · 2026
- computing 2026 dhs prelim p2 qnExam Papers · 2026
- computing 2026 dhs prelim p1 qnExam Papers · 2026
- computing 2026 asrjc prelim p1 qnExam Papers · 2026
- computing 2026 acjc prelim p2 qnExam Papers · 2026
- computing 2026 acjc prelim p1 qnExam Papers · 2026
- NYJC 2026 Prelim P2Exam Papers · 2026
- NYJC 2026 Prelim P1Exam Papers · 2026
- DHS 2026 Y6 H2 Computing Prelim Paper 2_finalExam Papers · 2026
- ACJC 2026 JC2 Computing Prelim Paper 2 (Practical)Exam Papers · 2026
- See all H2 Computing notes

