9618/42 · May/June 2022 · Worked solutions

Step-by-step solutions based on the mark scheme (not a mark-scheme dump).

Question 1

Paper page 2 for Q1
Original paper page 2

Part 1(a) — solution

  1. declaring array StackData and pointer StackPointer as (global data structures)
  2. StackData has 10 integer elements
  3. StackPointer initialised to 0

Visual Basic (VB.NET)

Dim StackData(9) As Integer
               Dim StackPointer As Integer
               Sub Main()
                 StackPointer = 0
               end Sub

Python

global StackData #integer
               global StackPointer
               StackData = [0,0,0,0,0,0,0,0,0,0] #integer
               StackPointer = 0

Mark points

  • declaring array StackData and pointer StackPointer as (global data structures)
  • StackData has 10 integer elements
  • StackPointer initialised to 0

Part 1(b) — solution

  1. procedure header with sensible identifier (and end where appropriate)
  2. outputting StackPointer
  3. outputting all 10 elements in array

Visual Basic (VB.NET)

Sub PrintArray()
                       Console.WriteLine(StackPointer)
                       For x = 0 To 9
                            Console.WriteLine(StackData(x))
                       Next
               End Sub

Python

def PrintArray():
                   global StackData
                   global StackPointer
                   print(StackPointer)
                   for x in range (0, 10):
                       print(StackData[x])

Mark points

  • procedure header with sensible identifier (and end where appropriate)
  • outputting StackPointer
  • outputting all 10 elements in array

Part 1(c) — solution

  1. function Push() taking an integer parameter
  2. checking if stack is full …
  3. …and returning FALSE
  4. (if not full) storing parameter to stack at StackPointer …
  5. …incrementing StackPointer
  6. …returning TRUE

Visual Basic (VB.NET)

Function Push(DataToPush)
                 If StackPointer = 10 Then
                   Return False
                 Else
                   StackData(StackPointer) = DataToPush
                   StackPointer = StackPointer + 1
                   Return True
                 End If
               End Function

Python

def Push(DataToPush):
                   global StackData
                   global StackPointer
                   if StackPointer == 10:
                       return False
                   else:
                       StackData[StackPointer] = DataToPush
                       StackPointer = StackPointer + 1
                       return True

 2022                                                         Page 6 of 36

9618/42                                Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • function Push() taking an integer parameter
  • checking if stack is full …
  • …and returning FALSE
  • (if not full) storing parameter to stack at StackPointer …
  • …incrementing StackPointer
  • …returning TRUE

Part 1(c) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 1(d)(i) — solution

  1. Inputting 11 numbers …
  2. …calling Push() with each number input as a parameter …
  3. …outputting appropriate message if TRUE returned
  4. …outputting appropriate message if FALSE returned
  5. Calling their output procedure after all 11 additions

Visual Basic (VB.NET)

Sub Main()
                 StackPointer = 0
                 Dim TempNumber As Integer
                 For x = 0 To 10
                   Console.WriteLine("Enter a number")
                   TempNumber = Console.ReadLine()

                   If Push(TempNumber) Then
                      Console.WriteLine("Stored")
                   Else
                      Console.WriteLine("Stack full")
                   End If
                 Next
                 PrintArray()
                 Console.ReadLine()
               End Sub

 2022                                                               Page 8 of 36

9618/42                                Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • Inputting 11 numbers …
  • …calling Push() with each number input as a parameter …
  • …outputting appropriate message if TRUE returned
  • …outputting appropriate message if FALSE returned
  • Calling their output procedure after all 11 additions

Part 1(d)(i) — solution

  1. StackPointer = 0
  2. StackData = [0,0,0,0,0,0,0,0,0,0]
  3. TempNumber = int(input("Enter a number"))
  4. if Push(TempNumber) == True:

Python

#main
               StackPointer = 0
               StackData = [0,0,0,0,0,0,0,0,0,0]
               for x in range(0, 11):
                   TempNumber = int(input("Enter a number"))

                   if Push(TempNumber) == True:
                       print("Stored")
                   else:
                       print("Stack full")
               PrintArray()

Mark points

  • StackPointer = 0
  • StackData = [0,0,0,0,0,0,0,0,0,0]
  • TempNumber = int(input("Enter a number"))
  • if Push(TempNumber) == True:

Part 1(d)(ii) — solution

1 mark for inputting all 11 numbers, message for first 10 saying added (11 to 20), message stating 11th number stating 1 stack full. Full array contents output (11 12 13 14 15 16 17 18 19 20). e.g. 2022 Page 10 of 36 9618/42 Cambridge International AS & A Level – Mark Scheme May/June 2022

Mark points

  • Include the ideas shown in the solution above.

Part 1(e)(i) — solution

  1. Pop() function header (and close where appropriate) and returning a number in all possible situations
  2. checking if stack is empty (StackPointer is 0) and returning -1
  3. (otherwise) accessing the item at the top of the stack …
  4. …decrementing the stack pointer
  5. …returning the item removed

Visual Basic (VB.NET)

Function Pop()
                 Dim ReturnData As Integer
                 If StackPointer = 0 Then
                   Return -1
                 Else
                   ReturnData = StackData(StackPointer – 1)
                   StackPointer = StackPointer - 1
                   Return ReturnData
                 End If
               End Function

Python

def Pop():
                   global StackData
                   global StackPointer
                   if StackPointer == 0:
                       return -1
                   else:
                       ReturnData = StackData[StackPointer - 1]
                       StackPointer = StackPointer - 1
                       return ReturnData

 2022                                                       Page 11 of 36

9618/42                                         Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • Pop() function header (and close where appropriate) and returning a number in all possible situations
  • checking if stack is empty (StackPointer is 0) and returning -1
  • (otherwise) accessing the item at the top of the stack …
  • …decrementing the stack pointer
  • …returning the item removed

Part 1(e)(i) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 1(e)(ii) — solution

  1. output of before removed with 11 inputs
  2. output of stack (after, this could be 11–20, 11–18, or 11–18 then ‘null’ ‘null’s)

Mark points

  • output of before removed with 11 inputs
  • output of stack (after, this could be 11–20, 11–18, or 11–18 then ‘null’ ‘null’s)

Part 1 — solution

  1. function declaration taking appropriate parameters and recursive calls
  2. remainder of the function is accurate including appropriate DIV operator

Visual Basic (VB.NET)

Function BinarySearch(ByVal SearchArray(,) As Integer, Lower As Integer, Upper As Integer,
               SearchValue As Integer)
                 Dim Mid As Integer
                 If Upper >= 0 Then
                   Mid = (Lower + (Upper - 1)) \ 2
                   If SearchArray(0, Mid) = SearchValue Then
                     Return Mid
                   ElseIf SearchArray(0, Mid) > SearchValue Then
                     Return BinarySearch(SearchArray, Lower, Mid - 1, SearchValue)
                   Else
                     Return BinarySearch(SearchArray, Mid + 1, Upper, SearchValue)
                   End If
                 End If
                 Return -1
               End Function

Python

def BinarySearch(SearchArray, Lower, Upper, SearchValue):
                   if Upper >= 0:
                       Mid = int((Lower + (Upper - 1)) / 2)
                       If SearchArray[0][Mid] == SearchValue:
                           return Mid
                       elif SearchArray[0][Mid] > SearchValue:
                           return BinarySearch(SearchArray, Lower, Mid-1, SearchValue)
                       else:
                           return BinarySearch(SearchArray, Mid+1, Upper, SearchValue)
                   return -1

 2022                                                        Page 22 of 36

9618/42                                Cambridge International AS & A Level – Mark Scheme             May/June 2022

Mark points

  • function declaration taking appropriate parameters and recursive calls
  • remainder of the function is accurate including appropriate DIV operator

Question 2

Paper page 4 for Q2
Original paper page 4

Part 2(a) — solution

  1. in main local 2D array declared …
  2. … with 10  10 integer elements
  3. initialising all array elements to a number…
  4. …that is random between 1 and 100 (allow inclusive or exclusive)

Visual Basic (VB.NET)

Sub Main()
                 Dim Random As New Random
                 Dim ArrayData(10, 10) As Integer
                 For x = 0 To 9
                   For y = 0 To 9
                      ArrayData(x, y) = Random.Next(1, 100)
                   Next
                 Next
                 Console.ReadLine()
               End Sub

Python

import random
               #main
               ArrayData= [[0]*10 for i in range(10)] #integer
               for x in range(0, 10):
                   for y in range(0,10):
                       ArrayData[x][y] = random.randint(1, 100)

 2022                                                      Page 13 of 36

9618/42                                Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • in main local 2D array declared …
  • … with 10  10 integer elements
  • initialising all array elements to a number…
  • …that is random between 1 and 100 (allow inclusive or exclusive)

Part 2(a) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 2(b)(i) — solution

  1. 1st outer loop (dimension 1)
  2. 2nd loop (dimension 2)
  3. inner for loop for all second dimension
  4. Selection statement …
  5. …swapping the numbers correctly

Visual Basic (VB.NET)

Dim TempNumber As Integer
               Dim ArrayLength As Integer = 10
               For X = 0 To ArrayLength - 1
                 For Y = 0 To ArrayLength - 2
                   For Z = 0 To ArrayLength - Y - 2
                      if ArrayData(X, Z) > ArrayData(X, Z + 1) then
                        TempNumber = ArrayData(X, Z)
                        ArrayData(X, Z) = ArrayData(X, Z+1)
                        ArrayData(X, Z + 1) = TempNumber
                      end if
                   Next Z
                 Next Y
               Next X

Python

ArrayLength = 10
               for X in range(0, ArrayLength):
                   for Y in range(0, ArrayLength-1):
                          for Z in range(0, ArrayLength - Y - 1):
                               if(ArrayData[X][Z] > ArrayData[X][Z+1]):
                                   TempNumber = ArrayData[X][Z]
                                   ArrayData[X][Z] = ArrayData[X][Z+1]
                                   ArrayData[X][Z+1] = TempNumber
               Accept for MP5:
               ArrayData[X][Z], ArrayData[X][Z+1] = ArrayData[X][Z+1], ArrayData[X][Z]

 2022                                                      Page 15 of 36

9618/42                                Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • 1st outer loop (dimension 1)
  • 2nd loop (dimension 2)
  • inner for loop for all second dimension
  • Selection statement …
  • …swapping the numbers correctly

Part 2(b)(i) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 2(b)(ii) — solution

  1. procedure header (and end where appropriate)
  2. Outputting all 10  10 values with each 2nd dimension on a complete line
  3. Calling procedure before and after bubble sort

Visual Basic (VB.NET)

Sub Main()
                 Dim random As New Random
                 Dim ArrayData(10, 10) As Integer
                 For x = 0 To 9
                   For y = 0 To 9
                      ArrayData(x, y) = random.Next(1, 100)
                   Next
                 Next
                 Console.WriteLine("before")
                 printarray(ArrayData)

                 Dim TempNumber As Integer
                 Dim ArrayLength As Integer = 10
                 For X = 0 To ArrayLength - 1
                   For Y = 0 To ArrayLength - 2
                     For Z = 0 To ArrayLength - Y - 2
                        if ArrayData(X, Z) > ArrayData(X, Z + 1) then
                          TempNumber = ArrayData(X, Z)
                          ArrayData(X, Z) = ArrayData(X, Z+1)
                          ArrayData(X, Z + 1) = TempNumber
                        end if
                     Next Z
                   Next Y
                 Next X

                 Console.WriteLine("after")
                 printarray(ArrayData)
                 Console.ReadLine()
               End Sub

 2022                                                       Page 17 of 36

9618/42                                Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • procedure header (and end where appropriate)
  • Outputting all 10  10 values with each 2nd dimension on a complete line
  • Calling procedure before and after bubble sort

Part 2(b)(ii) — solution

  1. For x = 0 To 9
  2. For y = 0 To 9
  3. print(ArrayData[x][y], " ", end='')
  4. ArrayData= [[0]*10 for i in range(10)] #integer
  5. ArrayData[x][y] = random.randint(1, 100)
  6. ArrayLength = 10
  7. TempNumber = ArrayData[X][Z]
  8. ArrayData[X][Z] = ArrayData[X][Z+1]
  9. ArrayData[X][Z+1] = TempNumber

Python

import random

               def Printarray(ArrayData):
                   for x in range(0, 10):
                       for y in range(0, 10):
                           print(ArrayData[x][y], " ", end='')
                       print("")
               #main
               ArrayData= [[0]*10 for i in range(10)] #integer
               for x in range(0, 10):
                   for y in range(0,10):
                       ArrayData[x][y] = random.randint(1, 100)
               print("Before")
               printarray(ArrayData)
               ArrayLength = 10
               for X in range(0, ArrayLength):
                   for Y in range(0, ArrayLength):
                       for Z in range(0, ArrayLength - Y - 1):
                           if(ArrayData[X][Z] > ArrayData[X][Z+1]):
                                TempNumber = ArrayData[X][Z]
                                ArrayData[X][Z] = ArrayData[X][Z+1]
                                ArrayData[X][Z+1] = TempNumber

               print("After")
               Printarray(ArrayData)

 2022                                               Page 18 of 36

9618/42                                Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • For x = 0 To 9
  • For y = 0 To 9
  • print(ArrayData[x][y], " ", end='')
  • ArrayData= [[0]*10 for i in range(10)] #integer
  • ArrayData[x][y] = random.randint(1, 100)
  • ArrayLength = 10
  • TempNumber = ArrayData[X][Z]
  • ArrayData[X][Z] = ArrayData[X][Z+1]
  • ArrayData[X][Z+1] = TempNumber

Part 2(b)(ii) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 2(b)(ii) — solution

  1. TempNumber = ArrayData[X][Z];
  2. ArrayData[X][Z] = ArrayData[X][Z+1];
  3. ArrayData[X][Z + 1] = TempNumber;

Mark points

  • TempNumber = ArrayData[X][Z];
  • ArrayData[X][Z] = ArrayData[X][Z+1];
  • ArrayData[X][Z + 1] = TempNumber;

Part 2(b)(iii) — solution

1 mark for output showing array unsorted and then sorted on 1 of the dimensions 1 e.g. 2022 Page 21 of 36 9618/42 Cambridge International AS & A Level – Mark Scheme May/June 2022

Mark points

  • Include the ideas shown in the solution above.

Part 2(c)(i) — solution

1 mark for each completed statement (6) 8

Mark points

  • Include the ideas shown in the solution above.

Part 2(c)(i) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 2(c)(ii) — solution

  1. screenshot outputting the index when Number is found
  2. screenshot outputting –1 with a Number not found

Mark points

  • screenshot outputting the index when Number is found
  • screenshot outputting –1 with a Number not found

Question 3

Paper page 7 for Q3
Original paper page 7

Part 3(a) — solution

  1. Card class declaration (and end where appropriate)
  2. Both attributes (Number and Colour) declared with suitable data types …
  3. …as private
  4. correct constructor header (and end where appropriate) with two parameters …
  5. …both parameters assigned to the attributes

Visual Basic (VB.NET)

Class Card
                 Private Number As Integer
                 Private Colour As String
                 Sub New(Numberp, Colourp)
                   Number = Numberp
                   Colour = Colourp
                 End Sub
               End Class

Python

class Card:
                   #Number as Integer
                   #Colour as string
                   def __init__(self, Numberp, Colourp):
                       self.__Number = Numberp
                       self.__Colour = Colourp

 2022                                                       Page 25 of 36

9618/42                                Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • Card class declaration (and end where appropriate)
  • Both attributes (Number and Colour) declared with suitable data types …
  • …as private
  • correct constructor header (and end where appropriate) with two parameters …
  • …both parameters assigned to the attributes

Part 3(a) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 3(b) — solution

  1. 1 get method header (and close where appropriate) with no parameter …
  2. … returning attribute
  3. 2nd correct get method

Visual Basic (VB.NET)

Function GetNumber()
                   Return Number
                 End Function
                 Function GetColour()
                   Return Colour
                 End Function

Python

def GetNumber(self):
                       return self.__Number
                   def GetColour(self):
                       return self.__Colour

Mark points

  • 1 get method header (and close where appropriate) with no parameter …
  • … returning attribute
  • 2nd correct get method

Part 3(c) — solution

  1. Declaration of array with 30 elements of type Card
  2. Opening the text file CardValues.txt for read
  3. Looping until EOF/30 times
  4. Reading in all sets of 2 lines (number then colour) …
  5. …creating object of type Card…
  6. …with number and colour read in from file …
  7. …storing in next array element
  8. Try and catch for file handling…s
  9. ….with appropriate outputs
  10. Closing the file in a suitable place

Visual Basic (VB.NET)

Sub Main()
                 Dim CardArray(0 To 29) As Card
                 Dim NumberRead As Integer
                 Dim ColourRead As String

                   Try
                   Dim Filename As String = "CardValues.txt"
                   Dim FileReader As New System.IO.StreamReader(filename)
                     For x = 0 To 29
                       NumberRead = FileReader.ReadLine()
                       ColourRead = FileReader.ReadLine()
                       CardArray(x) = New Card(NumberRead, ColourRead)
                     Next
                     FileReader.close()
                     Catch ex As Exception

 2022                                                          Page 28 of 36

9618/42                                Cambridge International AS & A Level – Mark Scheme           May/June 2022

Mark points

  • Declaration of array with 30 elements of type Card
  • Opening the text file CardValues.txt for read
  • Looping until EOF/30 times
  • Reading in all sets of 2 lines (number then colour) …
  • …creating object of type Card…
  • …with number and colour read in from file …
  • …storing in next array element
  • Try and catch for file handling…s
  • ….with appropriate outputs
  • Closing the file in a suitable place

Part 3(c) — solution

  1. CardArray = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] #integer
  2. Filename = "CardValues.txt"
  3. File = open(Filename,'r')
  4. NumberRead = int(File.readline())
  5. ColourRead = File.readline()
  6. CardArray[x] = Card(NumberRead, ColourRead)

Python

CardArray = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] #integer

               try:
               Filename = "CardValues.txt"
               File = open(Filename,'r')
               for x in range(0,30):
               NumberRead = int(File.readline())
               ColourRead = File.readline()
               CardArray[x] = Card(NumberRead, ColourRead)

               File.close
               except IOError:
               print("Could not find file")

Mark points

  • CardArray = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] #integer
  • Filename = "CardValues.txt"
  • File = open(Filename,'r')
  • NumberRead = int(File.readline())
  • ColourRead = File.readline()
  • CardArray[x] = Card(NumberRead, ColourRead)

Part 3(c) — solution

catch(FileNotFoundException ex){ } catch(IOException ex){ } } 2022 Page 30 of 36 9618/42 Cambridge International AS & A Level – Mark Scheme May/June 2022

Mark points

  • Include the ideas shown in the solution above.

Part 3(d) — solution

  1. Implementing a suitable way of storing which card have been selected
  2. Function ChooseCard() header (and close) and returning an integer (index) in all cases
  3. Reading in array index from the user …
  4. …with suitable validation looping until it is between 1 and 30 (inclusive)
  5. Converting input to array index (e.g. –1 each time)
  6. Check if the input is already selected…
  7. … if it is selected, loop until index input is not already selected
  8. … returning index of available card selected
  9. Stores the valid Card chosen as taken (using any suitable method)

Visual Basic (VB.NET)

Dim NumbersChosen(0 To 29) As Boolean
               Sub Main()
                  For x = 0 To 29
                    NumbersChosen(x) = False
                  Next
               ….
               End Sub
               Function chooseCard()
                  Dim CardSelected As Integer
                  Dim flagContinue As Boolean = True
                  While flagContinue = True
                    Console.WriteLine("Select a Card from 1 to 30")
                    CardSelected = Console.ReadLine()
                    If CardSelected < 1 Or CardSelected > 30 Then
                       Console.WriteLine("Number must be between ")

 2022                                                             Page 31 of 36

9618/42                                Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • Implementing a suitable way of storing which card have been selected
  • Function ChooseCard() header (and close) and returning an integer (index) in all cases
  • Reading in array index from the user …
  • …with suitable validation looping until it is between 1 and 30 (inclusive)
  • Converting input to array index (e.g. –1 each time)
  • Check if the input is already selected…
  • … if it is selected, loop until index input is not already selected
  • … returning index of available card selected
  • Stores the valid Card chosen as taken (using any suitable method)

Part 3(d) — solution

  1. ElseIf NumbersChosen(CardSelected - 1) = True Then
  2. flagContinue = False
  3. NumbersChosen(CardSelected - 1) = True
  4. flagContinue = True
  5. while flagContinue == true:
  6. CardSelected = int(input("Select a Card from 1 to 30"))
  7. elif NumbersChosen(CardSelected - 1) == True:
  8. flagContinue = False
  9. NumbersChosen[CardSelected-1] = True
  10. NumbersChosen = [False for i in range(30)]

Python

global NumbersChosen
               …
               def chooseCard ():
                   global NumbersChosen
                   flagContinue = True
                   while flagContinue == true:
                       CardSelected = int(input("Select a Card from 1 to 30"))
                       if CardSelected < 1 or CardSelected > 30:
                           print("Number must be between 1 and 30")
                       elif NumbersChosen(CardSelected - 1) == True:
                           print("Already taken")
                       else:
                           print("Valid")
                           flagContinue = False
                   NumbersChosen[CardSelected-1] = True
                   return CardSelected-1
               …
               #main
               …
               NumbersChosen = [False for i in range(30)]

 2022                                               Page 32 of 36

9618/42                                  Cambridge International AS & A Level – Mark Scheme   May/June 2022

Mark points

  • ElseIf NumbersChosen(CardSelected - 1) = True Then
  • flagContinue = False
  • NumbersChosen(CardSelected - 1) = True
  • flagContinue = True
  • while flagContinue == true:
  • CardSelected = int(input("Select a Card from 1 to 30"))
  • elif NumbersChosen(CardSelected - 1) == True:
  • flagContinue = False
  • NumbersChosen[CardSelected-1] = True
  • NumbersChosen = [False for i in range(30)]

Part 3(d) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 3(e)(i) — solution

  1. declaring array Player1 of type Card
  2. calling the function ChooseCard() four times
  3. storing the card, that is in the index returned, in the array Player1
  4. outputting all four numbers and colours in Player1 …
  5. …. using the get methodss

Visual Basic (VB.NET)

Dim Player1(0 To 3) As Card
               For x = 0 To 3
                 Player1(x) = CardArray(ChooseCard(NumbersChosen))
               Next
               for x = 0 to 3
                 console.writeline(Player1(x).GetColour)
                 console.writeline(Player1(x).GetNumber)
               next x

Python

Player1 = [] #of type Card
               for x in range(0, 4):
                   ReturnNumber = ChooseCard ()
                   Player1.append(CardArray[ReturnNumber])
               for x in range(0, 4):
                   print(Player1[x].GetColour())
                   print(Player1[x].GetNumber())

 2022                                                         Page 34 of 36

9618/42                                        Cambridge International AS & A Level – Mark Scheme               May/June 2022

Mark points

  • declaring array Player1 of type Card
  • calling the function ChooseCard() four times
  • storing the card, that is in the index returned, in the array Player1
  • outputting all four numbers and colours in Player1 …
  • …. using the get methodss

Part 3(e)(i) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 3(e)(ii) — solution

1 mark for both tests 1 Test 1: inputting 1, 5, 9, 10. Outputting: 1 red 9 green 9 orange 10 red Test 2: inputting 2 2 3 4 4 5. Outputting: 2 already taken. Then 5 black 2 while 4 red 9 green Test 1 e.g. 2022 Page 35 of 36 9618/42 Cambridge International AS & A Level – Mark Scheme May/June 2022

Mark points

  • Include the ideas shown in the solution above.

Part 3(e)(ii) — solution

Test 2 e.g. 2022 Page 36 of 36

Mark points

  • Include the ideas shown in the solution above.