8. 2D Lists

  • Feel free to use your laptop

  • You are strongly encourage to work with others

    • When you get stuck, ask those sitting around you for help

    • Get used to working together in the labs

    • Peer teaching and peer learning has been empirically shown to be very effective

8.1. Pre Lab Exercises

  • 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 print_row(mat, row):
    print(mat[row][0])
    print(mat[row][1])
    print(mat[row][2])

Given the following code:

two_dimensional = [['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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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

    four_x_four = [['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