8. 2D Lists

  • Feel free to use your laptop if you have it

  • Ensure I have recorded your completion — failure to do so will result in a grade of 0

  • I strongly encourage you to work with others in the lab

    • When you get stuck, do me a favour and ask those sitting around you for help

    • I want people to get used to working together in the labs

    • Peer teaching and peer learning is super effective

Note

To obtain full marks for the lab, you must:

  1. Have completed the pre-lab exercises

  2. Have been working on the lab content

  3. Demonstrate competency in the topics

8.1. Pre Lab Exercises

Warning

You must have completed the specified exercises prior to the start of the lab. If you have not come to lab prepared, you will be asked to leave and you will obtain a grade of 0 for the lab.

  • For all exercises

    • Do not make a vector.py file, just use Colab like you have been

    • Use assert to test instead of their test function

  1. Chapter 11 exercise(s)

    • 7

    • 8

  2. Write assertion tests for each of your functions above

8.2. Before Kattis

Note

Although the below example is a 3x3 matrix (list of lists), your functions should work on any sized matrix. For example, 4x4, 5x23, 230x19973.

In other words, the following is not correct as it will only ever work for a 3x3 matrix.

def printRow(mat, row):
    print(mat[row][0])
    print(mat[row][1])
    print(mat[row][2])

Given the following code:

twoD = [['a', 'b', 'c'],
        ['d', 'e', 'f'],
        ['g', 'h', 'i']]
  1. Write a function print_row(matrix, row: int):

    • matrix is a list of lists (2D list)

    • row is the specified row to print

    • The function will print out the values from the specified row

    • Each value can be on its own line

    • The function will not return anything

    • Verify correctness by running the function on multiple 2D lists

../../_images/matRow.png
  1. Write a function print_column(matrix, column: int):

    • matrix is a list of lists (2D list)

    • column is the specified column to print

    • The function will print out the values from the specified column

    • Each value can be on its own line

    • The function will not return anything

    • Verify correctness by running the function on multiple 2D lists

../../_images/matCol.png
  1. Write a function print_down_right(matrix):

    • matrix is a list of lists (2D list)

    • The function will print out the values of the matrix diagonal starting in the top left moving down to the right

    • Each value can be on its own line

    • The function will not return anything

    • Verify correctness by running the function on multiple 2D lists

../../_images/matDiag3.png
  1. Write a function print_up_right(matrix):

    • matrix is a list of lists (2D list)

    • The function will print out the values of the matrix diagonal starting in the bottom left moving up to the right

    • Each value can be on its own line

    • The function will not return anything

    • Verify correctness by running the function on multiple 2D lists

../../_images/matDiag4.png
  1. Write a function print_down_left(matrix):

    • matrix is a list of lists (2D list)

    • The function will print out the values of the matrix diagonal starting in the top right moving down to the left

    • Each value can be on its own line

    • The function will not return anything

    • Verify correctness by running the function on multiple 2D lists

../../_images/matDiag5.png
  1. Write a function print_up_left(matrix):

    • matrix is a list of lists (2D list)

    • The function will print out the values of the matrix diagonal starting in the bottom right moving up to the left

    • Each value can be on its own line

    • The function will not return anything

    • Verify correctness by running the function on multiple 2D lists

../../_images/matDiag6.png
  1. To verify that your functions work on arbitrary sized 2D lists, what happens if you run your functions with the following matrix?

    • Ensure each function works as expected

    • If the functions are only printing out three values, there is something wrong

    fourXfour = [['a', 'b', 'c', 'w'],
                 ['d', 'e', 'f', 'x'],
                 ['g', 'h', 'i', 'y'],
                 ['j', 'k', 'l', 'z']]
    

8.3. Kattis Problems

  • You should be using a scrap piece of paper to work out the ideas for the following problems

    • The problems you are to solve are getting too complex to try to solve by just coding

    • Trying to solve problems by just typing away will not yield success

  1. https://open.kattis.com/problems/bijele

  2. https://open.kattis.com/problems/cold

  3. https://open.kattis.com/problems/nastyhacks

  4. https://open.kattis.com/problems/grassseed

  5. https://open.kattis.com/problems/pet

  6. https://open.kattis.com/problems/batterup

  7. https://open.kattis.com/problems/aboveaverage

  8. https://open.kattis.com/problems/icpcawards

  9. https://open.kattis.com/problems/quickbrownfox

  10. https://open.kattis.com/problems/nodup

  11. https://open.kattis.com/problems/conundrum

  12. https://open.kattis.com/problems/bela

  13. https://open.kattis.com/problems/kornislav

Warning

Ensure that your your completion has been recorded. Failure to do so may result in a grade of 0.