Arrays
Arrays
CSC1015S Assignment 9
Arrays
Assignment Instructions
This assignment involves constructing Python programs that manipulate lists, dictionaries and
strings. You can use the following built-in functions in Python: map(), math.sqrt(),
split().
NOTE Your solutions to this assignment will be evaluated for correctness and for the following
qualities:
• Documentation
o Use of comments at the top of your code to identify program purpose,
author and date.
o Use of comments within your code to explain each non-obvious functional
unit of code.
• General style/readability
o The use of meaningful names for variables and functions.
• Algorithmic qualities
o Efficiency, simplicity
These criteria will be manually assessed by a tutor and commented upon. In this assignments, up to
10 marks will be deducted for deficiencies.
Page 1 of 5
Version 22/09/2023 08:32:40
Oge
Christopher
DONE
Right-aligned list:
Tumelo
Marcus
Rufaro
Dominique
Amanda
Elizabeth
Panayioti
Amiera
Absolom
Oge
Christopher
Write a module of utility functions called util.py for manipulating 2-dimensional arrays of size
4x4. (These functions will be used in Question 3.)
def create_grid(grid):
"""create a 4x4 array of zeroes within grid"""
False"""
Page 2 of 5
Version 22/09/2023 08:32:40
Use the testutil.py test program to test your functions. This program takes a single integer
input value and runs the corresponding test on your module. This is a variant of unit testing, where
test cases are written in the form of a program that tests your program. You will learn more about
unit testing in future CS courses.
Sample IO (The input from the user is shown in bold font – do not program this):
2
+--------------------+
|2 2 |
| 4 8 |
| 16 128 |
|2 2 2 2 |
+--------------------+
Sample IO (The input from the user is shown in bold font – do not program this):
7
True
Sample IO (The input from the user is shown in bold font – do not program this):
17
4 4
16 16
2 2
64 4
64 16
64 2
Sample IO (The input from the user is shown in bold font – do not program this):
9
True
Sample IO (The input from the user is shown in bold font – do not program this):
18
True
Page 3 of 5
Version 22/09/2023 08:32:40
2048 is a puzzle game where the goal is to repeatedly merge adjacent numbers in a grid until the
number 2048 is found. Your task in this question is to complete the code for a 2048 program, using
the utility module (util.py) from Question 2 and a supplied main program (2048.py).
The heart of the game is the set of merging functions that merge adjacent equal values and
eliminate gaps - you are required ONLY to write these functions in a module named push.py:
Note:
• • The check_won() function from util.py assumes you have won when you reach 32 -
this is simply to make testing easier.
• • The random number generator has been set to generate the same values each time for
testing purposes.
Page 4 of 5
Version 22/09/2023 08:32:40
Sample IO (The input from the user is shown in bold font – do not program this):
+--------------------+
| |
| |
| 2 |
|2 |
+--------------------+
Enter a direction:
l
+--------------------+
| |
| |
|2 |
|2 2 |
+--------------------+
Enter a direction:
u
+--------------------+
|4 2 |
| |
| |
| 4 |
+--------------------+
Enter a direction:
d
+--------------------+
| 2 |
| |
| |
|4 4 2 |
+--------------------+
Enter a direction:
r
+--------------------+
| 2 |
| |
| 2 |
| 8 2 |
+--------------------+
Enter a direction:
x
Submission
Create and submit a Zip file called ‘ABCXYZ123.zip’ (where ABCXYZ123 is YOUR student number)
containing right-align.py, util.py, and push.py.
Page 5 of 5