0% found this document useful (0 votes)
12 views

20an Algorith

The document describes a computer game where 6 players are seated around a table numbered 1 to 6. The players' names are stored in an array called PlayerName with the array index corresponding to the seat number. During the game, players can move clockwise around the table by a given number of spaces. The task is to write an algorithm to update the PlayerName array after a move. The algorithm should allow input of the number of spaces to move, use iteration, and ensure all names are moved to the correct positions. An example algorithm is provided that uses a temporary variable and for loop to shift the names the correct number of spaces clockwise through the array.

Uploaded by

Seher Farouk ZG
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

20an Algorith

The document describes a computer game where 6 players are seated around a table numbered 1 to 6. The players' names are stored in an array called PlayerName with the array index corresponding to the seat number. During the game, players can move clockwise around the table by a given number of spaces. The task is to write an algorithm to update the PlayerName array after a move. The algorithm should allow input of the number of spaces to move, use iteration, and ensure all names are moved to the correct positions. An example algorithm is provided that uses a temporary variable and for loop to shift the names the correct number of spaces clockwise through the array.

Uploaded by

Seher Farouk ZG
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

009 An algorithm a day…

Algorithm Question Source: OCR GCSE Computing Exam June 2015

A computer game shows 6 players around a table on seats. They are


numbered 1 to 6.

The names of the players are stored in an array with 6 elements called PlayerName. The index position of the array is
used to indicate the seat number. For example, the value of PlayerName(1) is ‘Helen’.
During the game, each player sometimes moves clockwise by a given number of places.
For example, if the number of places is 2, Helen will move to seat 3, Priya will move to seat 1 etc.
Write an algorithm, which updates the contents of the array ‘PlayerMove’ after a move has occurred. The algorithm
should:
- Allow the number of places to move to be input
- Use iteration
- Ensure that all of the players’ names are moved to the correct position in the array.
[6 marks]
Algorithm Example Answer
A computer game shows 6 players around a table on seats. They are numbered
1 to 6.

The names of the players are stored in an array with 6 elements called PlayerName. The index position of the array is
used to indicate the seat number. For example, the value of PlayerName(1) is ‘Helen’.
During the game, each player sometimes moves clockwise by a given number of places.
For example, if the number of places is 2, Helen will move to seat 3, Priya will move to seat 1 etc.
Write an algorithm, which updates the contents of the array ‘PlayerMove’ after a move has occurred. The algorithm
should:
- Allow the number of places to move to be input
- Use iteration
- Ensure that all of the players’ names are moved to the correct position in the array. [6 marks]
***There are always different ways to solve a problem. This algorithm is just an example. What is
important is that the logic is correct!***

LOGIC:

- Input the number of places to move (e.g. Num)


- Use of temporary variable(s) or second array to
- Avoid overwriting values in the array
- Sensible use of a loop
- ... with correct end condition
- Correctly deals with moving from position 1 (e.g. 1 + Num) - Correctly deals with moving
from position 6 (e.g. Num )

EXAMPLE ALGORITHM:

num = int(input(“Enter number: ”))


for loop = 1 to num

temp = playerName[6]

playerName[6] = playerName[5]

playerName[5] = playerName[4]

playerName[4] = playerName[3]

playerName[3] = playerName[2]

playerName[2] = playerName[1]

playerName[1] = temp
next i

You might also like