0% found this document useful (0 votes)
26 views8 pages

Quiz 6

The document outlines the requirements for COMP9021's Coding Quiz 6, which involves implementing a function to determine the size of the largest parallelogram with horizontal sides in a randomly generated 10x10 grid of 0s and 1s. The quiz is worth 4 marks and is due on July 25, 2024, with late submissions allowed under specific conditions. Sample test cases are provided to illustrate the expected output of the function.

Uploaded by

huangde1212
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views8 pages

Quiz 6

The document outlines the requirements for COMP9021's Coding Quiz 6, which involves implementing a function to determine the size of the largest parallelogram with horizontal sides in a randomly generated 10x10 grid of 0s and 1s. The quiz is worth 4 marks and is due on July 25, 2024, with late submissions allowed under specific conditions. Sample test cases are provided to illustrate the expected output of the function.

Uploaded by

huangde1212
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

COMP9021 Principles of Programming

Term 2, 2024
Coding Quiz 6
Worth 4 marks and due Week 9 Thursday @ 9pm

Description
You are provided with a stub in which you need to insert your code where indicated without doing
any changes to the existing code to complete the task. Although it is not needed for this quiz, you
may import any extra module that is already installed in Ed if you wish.

Given the value of seed and density, the provided code randomly fills an array (or grid) of size
10 x 10 with 0s and 1s.

You need to determine and output the size of the largest parallelogram with horizontal sides. A
parallelogram with horizontal sides consists of a line with at least 2 consecutive 1s, with below at
least one line with the same number of consecutive 1s, all those lines being aligned vertically in
which case the parallelogram is a rectangle, for instance:

1 1 1
1 1 1
1 1 1
1 1 1

or consecutive lines move to the left by one position, for instance:

1 1 1
1 1 1
1 1 1
1 1 1

or consecutive lines move to the right by one position, e.g.

1 1 1
1 1 1
1 1 1
1 1 1

The size is the number of 1s in the parallelogram. In the above examples, the size is 12.

1
Your task is to implement the function called size_of_largest_parallelogram().

You may possibly define other functions.

The provided stub and the outputs of the sample test cases explain the task to be performed.

Marking

size_of_largest_parallelogram() 4 marks

-------------------------------------------------------------

Total 4 marks

Due Date and Submission


Quiz 6 is due Week 9 Thursday 25 July 2024 @ 9.00pm (Sydney time).
Note that late submission with 5% penalty per day is allowed up to 3 days from the due date, that
is, any late submission after Week 9 Sunday 28 July 2024 @ 9pm will be discarded.
Make sure not to change the filename quiz_6.py while submitting by clicking on [Mark] button
in Ed. It is your responsibility to check that your submission did go through properly using
Submissions link in Ed otherwise your mark will be zero for Quiz 6.

2
Test Cases

$ python quiz_6.py
Enter two integers, the second one being strictly positive: 0 1
Here is the grid that has been generated:
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
There is no parallelogram with horizontal sides

$ python quiz_6.py
Enter two integers, the second one being strictly positive: 0 2
Here is the grid that has been generated:
110 1 1 1 1 110
010 0 1 0 1 001
101 1 1 0 1 110
001 0 1 1 0 100
000 1 0 0 1 101
101 0 1 1 0 110
100 0 0 1 1 000
000 1 1 0 0 111
110 1 0 1 1 000
100 1 0 1 1 000

The largest parallelogram with horizontal sides has a size of 4

3
$ python quiz_6.py
Enter two integers, the second one being strictly positive: 0 3
Here is the grid that has been generated:
110 1 1 1 1 111
101 0 1 0 0 111
110 1 0 1 0 111
101 1 1 1 1 011
111 0 1 0 0 111
110 1 1 1 0 111
001 0 0 0 1 100
111 0 1 1 1 101
110 1 1 1 1 101
111 0 1 0 0 001

The largest parallelogram with horizontal sides has a size of 12

$ python quiz_6.py
Enter two integers, the second one being strictly positive: 0 4
Here is the grid that has been generated:
110 1 1 1 1 111
111 0 1 1 1 001
101 1 1 1 1 110
001 0 1 1 1 101
111 1 0 0 1 101
101 1 1 1 0 111
111 1 0 1 1 001
100 1 1 1 1 111
110 1 0 1 1 110
101 1 1 1 1 001

The largest parallelogram with horizontal sides has a size of 12

4
$ python3 quiz_6.py
Enter two integers, the second one being strictly positive: 1 4
Here is the grid that has been generated:
101 0 1 1 1 110
101 1 0 1 1 101
000 0 1 1 1 011
111 1 1 1 1 010
110 1 1 1 1 111
011 1 1 1 1 101
011 1 1 0 1 011
111 0 1 1 1 111
101 1 1 1 0 111
111 1 1 0 1 101
The largest parallelogram with horizontal sides has a size of 16

$ python3 quiz_6.py
Enter two integers, the second one being strictly positive: 0 5
Here is the grid that has been generated:
110 1 1 1 1 111
111 1 1 1 0 111
111 0 0 1 1 101
111 1 1 1 1 110
100 1 0 1 1 111
011 1 1 1 1 100
111 0 1 1 1 011
111 1 1 1 1 011
111 1 1 1 1 011
100 1 1 0 0 111

The largest parallelogram with horizontal sides has a size of 15.

5
Test Cases Explained

$ python quiz_6.py
Enter two integers, the second one being strictly positive: 0 1
Here is the grid that has been generated:
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
000 0 0 0 0 000
There is no parallelogram with horizontal sides

$ python quiz_6.py
Enter two integers, the second one being strictly positive: 0 2
Here is the grid that has been generated:
110 1 1 1 1 110
010 0 1 0 1 001
101 1 1 0 1 110
001 0 1 1 0 100
000 1 0 0 1 101
101 0 1 1 0 110
100 0 0 1 1 000
000 1 1 0 0 111
110 1 0 1 1 000
100 1 0 1 1 000

The largest parallelogram with horizontal sides has a size of 4

6
$ python quiz_6.py
Enter two integers, the second one being strictly positive: 0 3
Here is the grid that has been generated:
110 1 1 1 1 111
101 0 1 0 0 111
110 1 0 1 0 111
101 1 1 1 1 011
111 0 1 0 0 111
110 1 1 1 0 111
001 0 0 0 1 100
111 0 1 1 1 101
110 1 1 1 1 101
111 0 1 0 0 001

The largest parallelogram with horizontal sides has a size of 12

$ python quiz_6.py
Enter two integers, the second one being strictly positive: 0 4
Here is the grid that has been generated:
110 1 1 1 1 111
111 0 1 1 1 001
101 1 1 1 1 110
001 0 1 1 1 101
111 1 0 0 1 101
101 1 1 1 0 111
111 1 0 1 1 001
100 1 1 1 1 111
110 1 0 1 1 110
101 1 1 1 1 001

The largest parallelogram with horizontal sides has a size of 12

7
$ python quiz_6.py
Enter two integers, the second one being strictly positive: 1 4
Here is the grid that has been generated:
101 0 1 1 1 110
101 1 0 1 1 101
000 0 1 1 1 011
111 1 1 1 1 010
110 1 1 1 1 111
011 1 1 1 1 101
011 1 1 0 1 011
111 0 1 1 1 111
101 1 1 1 0 111
111 1 1 0 1 101
The largest parallelogram with horizontal sides has a size of 16

$ python quiz_6.py
Enter two integers, the second one being strictly positive: 0 5
Here is the grid that has been generated:
110 1 1 1 1 111
111 1 1 1 0 111
111 0 0 1 1 101
111 1 1 1 1 110
100 1 0 1 1 111
011 1 1 1 1 100
111 0 1 1 1 011
111 1 1 1 1 011
111 1 1 1 1 011
100 1 1 0 0 111

The largest parallelogram with horizontal sides has a size of 15

You might also like