AQA A-Level Computer Science Paper 1, June 2025: Question 12
14 marks · Hard difficulty · Programming
Implement a new subroutine CanGetATargetUsingThreeNumbers to determine if a target value can be made from three available numbers, amend DisplayState to show the result, provide test output, and calculate the total number of valid three-number expressions.
Practise this questionQuestion
Question text
12 This question extends the Skeleton Program so that the program will tell the player if
they can make one of the targets using an expression that contains exactly three of
the values from the numbers available.
Your program does not need to work with the exponentiation operator from
Question 10.
What you need to do
Task 1
Create a new subroutine called CanGetATargetUsingThreeNumbers that will
return True if it is possible to create an expression using exactly three of the values
in NumbersAllowed that matches any of the targets shown to the player.
Otherwise, it should return False.
Task 2
Modify the DisplayState subroutine so that it calls the subroutine
CanGetATargetUsingThreeNumbers and then displays an appropriate
message saying if it is possible or not to make one of the targets using exactly three
of the values from the available numbers.
Task 3
Test that the changes you have made work:
• run the Skeleton Program
• select the training game
• enter 3+8–2
Evidence that you need to provide
Include the following evidence in your Electronic Answer Document.
12.1 Your PROGRAM SOURCE CODE for the new subroutine
CanGetATargetUsingThreeNumbers and the amended DisplayState
subroutine.
[11 marks]
12.2 SCREEN CAPTURE(S) showing the requested test.
[1 mark]
12.3 State how many valid expressions there are that use exactly three numbers.
You should assume that all the numbers available are different and that the
exponentiation operator from Question 10 has not been used.
You should show your working.
[2 marks]
END OF QUESTIONS
Mark scheme
Show the mark scheme
Question Marks
12 1 All marks for AO3 (programming) 11
Mark points 1 to 9 relate to the CanGetATargetUsingThreeNumbers
subroutine.
Mark points 10 to 11 relate to the DisplayState subroutine.
1. Creating a new subroutine called CanGetATargetUsingThreeNumbers;
R. other subroutine identifiers I. case and minor typos
2. Iterative structure that repeats once for each target; A. equivalent
3. Selection structure that means targets of –1 will be ignored;
4. Nested iteration structures to get three positions in NumbersAllowed //
nested iteration structures to get three numbers from NumbersAllowed;
5. Checks that the three positions from mark point 4 are all different // checks that
the three numbers do not exceed the count of that number in
NumbersAllowed;
6. Nested iteration to get two operators; A. equivalent
7. Forms an infix expression using three numbers from NumbersAllowed and
two operators; R. if expressions cannot be formed for an operator
8. Converts expression to RPN and evaluates it // evaluates the infix expression;
R. if expressions cannot be evaluated for an operator
9. Selection structure that returns true if their attempt at evaluation of expression is
equal to a target and the subroutine returns false if no match is found; R.
returns false after only checking one expression/target
10. Call to new subroutine and uses value returned;
11. Selection structure(s) with condition based on value returned by call to new
subroutine and appropriate messages with exactly one of the two messages
being displayed under all circumstances; R. if would always display the same
message
Alternative solution
2. Attempts call to CheckIfUserInputEvaluationIsATarget in
appropriate place in the code;
3. Correct call to CheckIfUserInputEvaluationIsATarget including
ensuring that the score and list of targets are not changed by the call;
Max 10 if code contains any errors–A-LEVEL COMPUTER SCIENCE – –
12 2 Mark is for AO3 (evaluate) 1
**** SCREEN CAPTURE ****
Must match code from 12.1, including prompts on screen capture matching those
in code.
Code for 12.1 must be sensible.
Screen capture(s) showing that the message changes from can get a target to
cannot get a target after entering the expression; A. any appropriate messages
12 3 All marks AO2 (apply) 2
54 4 4 3 // 960;;
If final answer is incorrect award a maximum of 1 mark for:
• Multiplying by 4 twice
• Multiplying by 5, 4 and 3
• Multiplying by 5 and 12 – A-LEVEL COMPUTER SCIENCE – –
VB.Net
Question Marks
04 1 Console.Write("Enter the text to encrypt: ") 12
Dim Plaintext As String = Console.ReadLine()
Console.Write("Enter the grid size: ")
Dim GridSize As Integer = Console.ReadLine
Dim PTLettersOnly As String = ""
Dim Ciphertext As String = ""
For Count = 0 To Plaintext.Length - 1
If 25
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".Contains(Plai
ntext(Count)) Then
PTLettersOnly &= Plaintext(Count)
End If
Next
For Column = 0 To GridSize - 1
For Count = Column To PTLettersOnly.Length - 1 Step GridSize
Ciphertext &= PTLettersOnly(Count)
Next
Next
Console.Write(Ciphertext)
Console.ReadLine()
09 1 ... 4
Score -= 1
If Targets(1) <> -1 Then
Score -= 5
End If
If Targets(0) <> -1 Then
Score -= Targets(0) + 10
GameOver = True
Else
UpdateTargets(Targets, TrainingGame, MaxTarget)
End If
... – A-LEVEL COMPUTER SCIENCE – –
12 1 Function CanGetATargetUsingThreeNumbers(ByVal NumbersAllowed As 11
List(Of Integer), ByVal Targets As List(Of Integer)) As Boolean
Dim OperatorList As New List(Of String)({"+", "-", "*", "/"})
For Each T In Targets
If T <> -1 Then
For i = 0 To NumbersAllowed.Count - 1
For j = 0 To NumbersAllowed.Count - 1
For k = 0 To NumbersAllowed.Count - 1
If Not (i = j Or i = k Or j = k) Then
For Each w In OperatorList
For Each x In OperatorList
Dim UserInput As String =
NumbersAllowed(i).ToString & w & NumbersAllowed(j).ToString() & x &
NumbersAllowed(k).ToString()
Dim UserInputInRPN As List(Of String) =
ConvertToRPN(UserInput)
If T = EvaluateRPN(UserInputInRPN) Then
Return True
End If
Next
Next
26 End If
Next
Next
Next
End If
Next
Return False
End Function
Sub DisplayState(ByVal Targets As List(Of Integer), ByVal
NumbersAllowed As List(Of Integer), ByVal Score As Integer)
DisplayTargets(Targets)
DisplayNumbersAllowed(NumbersAllowed)
If CanGetATargetUsingThreeNumbers(NumbersAllowed, Targets) Then
Console.WriteLine("Can get a target when using exactly three of
the numbers available")
Else
Console.WriteLine("Can't get a target using exactly three of the
numbers available")
End If
DisplayScore(Score)
End Sub
– A-LEVEL COMPUTER SCIENCE – –
Python 3
Question Marks
04 1 Plaintext = input("Enter the text to encrypt: ") 12
GridSize = int(input("Enter the grid size: "))
PTLettersOnly = ""
Ciphertext = ""
for Count in range (0, len(Plaintext)):
if Plaintext[Count] in
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz":
PTLettersOnly += Plaintext[Count]
for Column in range (0, GridSize):
for Count in range(Column, len(PTLettersOnly), GridSize):
Ciphertext += PTLettersOnly[Count] 29
print(Ciphertext)
09 1 Score -= 1 4
if Targets[1] != -1:
Score -= 5
if Targets[0] != -1:
Score -= Targets[0] + 10
GameOver = True
else:
... – A-LEVEL COMPUTER SCIENCE – –
C#
Question Marks
04 1 Console.Write("Enter the text to encrypt: "); 12
string Plaintext = Console.ReadLine();
Console.Write("Enter the grid size: ");
int GridSize = Convert.ToInt32(Console.ReadLine());
string PTLettersOnly = "";
string Ciphertext = "";
for (int Count = 0; Count < Plaintext.Length; Count++)
{
if
("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".Contains(Pla
intext[Count]))
{
PTLettersOnly += Plaintext[Count];
}
}
for (int Column = 0; Column < GridSize; Column++)
{
for (int Count = Column; Count < PTLettersOnly.Length; Count +=
GridSize)
{
Ciphertext += PTLettersOnly[Count];
}
}
Console.Write(Ciphertext);
Console.ReadLine();
09 1 ... 4
30 Score--;
if (Targets[1] != -1)
{
Score -= 5;
}
if (Targets[0] != -1)
{
Score -= Targets[0] + 10;
GameOver = true;
}
else
{
UpdateTargets(Targets, TrainingGame, MaxTarget);
}
... – A-LEVEL COMPUTER SCIENCE – –
if (Operators.Count > 0 &&
Precedence[Operators[Operators.Count - 1]] ==
Precedence[CurrentOperator] && CurrentOperator != "^")
{
UserInputInRPN.Add(Operators[Operators.Count - 1]);
Operators.RemoveAt(Operators.Count - 1);
}
Operators.Add(CurrentOperator);
... – A-LEVEL COMPUTER SCIENCE – –
12 1 public static bool CanGetATargetUsingThreeNumbers(List<int> 11
NumbersAllowed, List<int> Targets)
{
List<string> OperatorList = new List<string> { "+", "-", "*", "/"
};
foreach (var T in Targets)
{
if (T != -1)
{
for (int i = 0; i < NumbersAllowed.Count; i++)
{
for (int j = 0; j < NumbersAllowed.Count; j++)
{
for (int k = 0; k < NumbersAllowed.Count; k++)
{
if (i != j && i != k && j != k)
{
foreach (var w in OperatorList)
{
foreach (var x in OperatorList)
{
string UserInput =
quot;{NumbersAllowed[i]}{w}{NumbersAllowed[j]}{x}{NumbersAllowed[k]}";List<string> UserInputInRPN =
ConvertToRPN(UserInput);
if (T == EvaluateRPN(UserInputInRPN))
{
return true;
}
}
}
}
}
}
}
}
}
return false;
}
static void DisplayState(List<int> Targets, List<int>
NumbersAllowed, int Score)
{
DisplayTargets(Targets);
DisplayNumbersAllowed(NumbersAllowed);
DisplayTargetMultiples(Targets);
if (CanGetATargetUsingThreeNumbers(NumbersAllowed, Targets))
{
Console.WriteLine("Can get a target when using exactly three of
the numbers available");
} 35
else
{
Console.WriteLine("Can't get a target using exactly three of the
numbers available");
}
DisplayScore(Score);
} – A-LEVEL COMPUTER SCIENCE – –
Java
Question Marks
04 1 System.out.print("Enter the plaintext: "); 12
String plainText = System.console().readLine();
String plainTextLetters = "";
for (int i = 0; i < plainText.length(); i++) {
if (Character.isLetter(plainText.charAt(i))) {
plainTextLetters += plainText.charAt(i);
}
}
System.out.print("Enter the number of columns: ");
int columns = Integer.parseInt(System.console().readLine());
System.out.print("Ciphertext is: ");
for (int column = 0; column < columns; column++) {
for (int i = column; i < plainTextLetters.length(); i +=
columns) {
System.out.print(plainTextLetters.charAt(i));
}
}
System.out.println();
System.console().readLine();
09 1 ... 4
score.value -= 1;
if (targets.get(1) != -1) {
score.value -= 5;
}
if (targets.get(0) != -1) {
score.value -= targets.get(0) + 10;
}
if (targets.get(0) != -1) {
gameOver = true;
} else {
updateTargets(targets, trainingGame, maxTarget);
}
... – A-LEVEL COMPUTER SCIENCE – –
11 1 static void displayTargetMultiples(List<Integer> targets) { 11
Map<Integer, Integer> counts = new HashMap<Integer, Integer>();
for (int t : targets) {
if (t != -1 && counts.containsKey(t)) {
counts.put(t, counts.get(t) + 1);
} else {
counts.put(t, 1);
}
}
System.out.print("Targets appearing more than once: ");
for (Map.Entry<Integer, Integer> count : counts.entrySet()) {
if (count.getValue() > 1) {
System.out.print(count.getKey() + " ");
}
}
System.out.println();
}
static void displayState(List<Integer> targets, List<Integer>
numbersAllowed, int score) {
38 displayTargets(targets);
displayNumbersAllowed(numbersAllowed);
displayTargetMultiples(targets);
displayScore(score);
} – A-LEVEL COMPUTER SCIENCE – –
12 1 static boolean canGetATargetUsingThreeNumbers(List<Integer> targets, 11
List<Integer> allowed) {
for (Integer n1 : allowed) {
for (Integer n2 : allowed) {
for (Integer n3 : allowed) {
String[] operators = {"+", "-", "*", "/"};
for (String op1 : operators) {
for (String op2 : operators) {
String expression = n1.toString() + op1 +
n2.toString() + op2 + n3.toString();
List<String> RPN = convertToRPN(expression);
IntWrapper score = new IntWrapper(0);
if
(checkNumbersUsedAreAllInNumbersAllowed(allowed, RPN, 1000) &&
checkIfUserInputEvaluationIsATarget(targets, RPN, score)) {
return true;
}
}
}
}
}
}
return false;
}
static void displayState(List<Integer> targets, List<Integer>
numbersAllowed, int score) {
if (canGetATargetUsingThreeNumbers(targets, numbersAllowed)) {
System.out.println("You can make a target using three
numbers");
} else {
System.out.println("You cannot make a target using three
numbers");
}
40 displayTargets(targets);
displayNumbersAllowed(numbersAllowed);
displayTargetMultiples(targets);
displayScore(score);
}
How to answer it
Question 12: Skeleton Program Extension & Combinatorics
Paper 1 Skeleton Code • Section D • Total 14 MarksWhat this question tests
This culminating question assesses your mastery over Paper 1 programming concepts and algorithmic problem-solving:
- Subroutine Design & Decomposition (AO3): Defining modular functions with appropriate parameters and return types.
- Combinatorial Search / Brute-Force Iteration: Using nested loops to exhaustively generate 3-number permutations without duplication of indexed elements.
- Integrating Skeleton Utilities: Reusing internal components such as ConvertToRPN and EvaluateRPN (or CheckIfUserInputEvaluationIsATarget ).
- Selection & UI Integration: Calling the function from DisplayState and outputting conditional status messages.
- Mathematical Analysis (AO2): Calculating the total number of permutations of operands and operators using the product rule of combinatorics.
Source Code: Subroutine Implementation & DisplayState Modification
Creating CanGetATargetUsingThreeNumbers and updating DisplayState
💡 Key Knowledge & Logic
You need to generate all candidate infix expressions consisting of exactly 3 different numbers from NumbersAllowed and two standard operators ( + , - , * , / ).
- Three Distinct Indices: Ensure i ≠ j , j ≠ k , and i ≠ k so no tile is reused beyond its availability.
- Target Validation: Targets equal to -1 (cleared/inactive targets) must be ignored.
- Return Semantics: Return True immediately upon the first successful match. Only return False after all combinations have been exhausted.
❌ Common Errors (Mark Scheme Traps)
- Premature Return: Returning False inside the loop after failing one calculation rather than outside all loops.
- Index Collisions: Checking values instead of indices (e.g., if the available pool contains two separate 2s, using index checks allows both, but value checks might fail).
- Calling Side-Effects: Modifying the user's actual score or mutating the live target list when evaluating hypothetical expressions.
- Casing & Identifiers: Spelling subroutine names incorrectly (e.g. lowercase letters).
✅ Model Implementation (Python / C# / VB.NET / Java Logic)
def CanGetATargetUsingThreeNumbers(NumbersAllowed, Targets): operators = ["+", "-", "*", "/"] # Iterate through all valid active targets for T in Targets: if T == -1: continue # Nested loops to select 3 distinct indices from NumbersAllowed for i in range(len(NumbersAllowed)): for j in range(len(NumbersAllowed)): for k in range(len(NumbersAllowed)): if i != j and i != k and j != k: # Combine with every combination of two operators for op1 in operators: for op2 in operators: expr = f"{NumbersAllowed[i]}{op1}{NumbersAllowed[j]}{op2}{NumbersAllowed[k]}" rpn = ConvertToRPN(expr) if EvaluateRPN(rpn) == T: return True return False # Amended DisplayState modification: def DisplayState(Targets, NumbersAllowed, Score): DisplayTargets(Targets) DisplayNumbersAllowed(NumbersAllowed) DisplayTargetMultiples(Targets) # Conditional message based on subroutine outcome if CanGetATargetUsingThreeNumbers(NumbersAllowed, Targets): print("Can get a target when using exactly three of the numbers available") else: print("Can't get a target using exactly three of the numbers available") DisplayScore(Score) - Create subroutine named exactly CanGetATargetUsingThreeNumbers
- Loop repeating once for each target
- Selection structure ensuring targets of -1 are ignored
- Nested iterations to select three positions from NumbersAllowed
- Validation that the three positions are all different (no number index reused)
- Nested iteration to test two operators
- Constructs an infix expression of format num op num op num
- Converts expression to RPN and evaluates it
- Returns True if evaluation equals target; returns False only after checking all options
- Subroutine correctly called within DisplayState and return value captured
- Correct selection statement in DisplayState outputting appropriate messages for both outcomes
Evidence: Screen Capture of Test Run
Testing user input with 3+8-2 in Training Game mode
🧠 Exam Technique
Follow every step in Task 3 precisely. The examiner looks for specific dynamic message transitions on the console screen:
- Select Training Game mode at startup.
- Prior to entering input, verify the screen displays: "Can get a target when using exactly three of the numbers available".
- Enter exactly: 3+8-2 .
- Observe that after targets are consumed, the prompt switches dynamically to: "Can't get a target using exactly three of the numbers available".
✅ Expected Terminal Output Display
Targets that appear multiple times: 23 34 119 Can get a target when using exactly three of the numbers available Current Score: 0 Enter an expression: 3+8-2 ||| 23| 9|140|82|121|34|45|68|75|34|23|119|43|23|119|119| Numbers available: 2 3 2 8 512 Targets that appear multiple times: 23 34 119 Can't get a target using exactly three of the numbers available Current Score: 1 Calculation: Number of Valid 3-Number Expressions
Combinatorics of selecting numbers and operators
📐 Step-by-Step Calculation
- Number of available number tiles: The skeleton program provides 5 numbers.
- Select 1st operand: 5 choices.
- Select 2nd operand (distinct): 4 choices remaining.
- Select 3rd operand (distinct): 3 choices remaining.
- Select 1st operator (+, -, *, /): 4 choices.
- Select 2nd operator (+, -, *, /): 4 choices (operators can be repeated).
- Total valid combinations: 5 × 4 × 4 × 4 × 3 = 960
❌ Common Errors & Calculation Traps
- Assuming operators cannot repeat: Operators are not consumed; all 4 remain available for both positions (hence 4 × 4 , not 4 × 3 ).
- Ignoring operand order (Combinations vs Permutations): The order of numbers matters because division and subtraction are non-commutative (e.g., 8 - 3 ≠ 3 - 8 ).
- Forgetting 1 mark partial credit: If final answer is wrong, 1 method mark is awarded for multiplying by 4 twice, multiplying by 5, 4, and 3, or multiplying by 5 and 12.
Topics
4.1 Fundamentals of programming · 4.4 Theory of computation · 4.13 Systematic approach to problem solving · 4.1.1 Programming · 4.4.1 Abstraction and automation · 4.4.4 Classification of algorithms · 4.13.1 Aspects of software development
Question and mark scheme from the AQA A-Level Computer Science examination, Paper 1, June 2025. QuestionVault is an independent revision resource; questions remain the copyright of the awarding body.