Quiz 6
Quiz 6
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
1 1 1
1 1 1
1 1 1
1 1 1
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().
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
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
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
$ 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
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
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
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
$ 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
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