Presentation is loading. Please wait.

Presentation is loading. Please wait.

TA SURVEY Have the TA write their name on the board Fill out the survey at: https://www.surveymonkey.com/s/TAOS_Fall2013 The TA should walk out 5 minutes.

Similar presentations


Presentation on theme: "TA SURVEY Have the TA write their name on the board Fill out the survey at: https://www.surveymonkey.com/s/TAOS_Fall2013 The TA should walk out 5 minutes."— Presentation transcript:

1 TA SURVEY Have the TA write their name on the board Fill out the survey at: https://www.surveymonkey.com/s/TAOS_Fall2013 The TA should walk out 5 minutes MAX  Still have a lot to do today!!

2 CMSC 201 MR. LUPOLI Problem Solving

3 Steps to Solve a Problem Read the problem completely many times. Solve the problem manually with a few sets of sample data. (or smaller pieces!!) Optimize the manual steps. Write the manual steps as comments or pseudo- code. Add to the comments or pseudo-code with real code. Optimize the real code.

4 Read the problem. Do not assume anything! Make sure to view the demonstration as well (if given) Instructions  Create directory lab12  Move to that directory and copy a file already created for you. cp /afs/umbc.edu/users/s/l/slupoli/pub/labCode201/lab12.py.

5 Reading the Problem Visit: http://projecteuler.net/problem=11http://projecteuler.net/problem=11 Read the problem In lab12.py  Describe the project you are about to start in the file header “description”

6 Reading the Problem Under your description of the project, within comments, list your questions ''' 1. When is this project due? 2. Will the grid always be 20 x 20? 3. Will each number be an integer? '''

7 Reading the Problem Why am I typing this inside the file?  Used a Comment  Can copy and paste to an email to my TA/instructor  Can add the answer later  A reminder

8 Using sample data Can we downsize the problem slightly  Usually we can, now more manageable  Make sure it has valid data and really tests your application  A new matrix of all 1’s is useless!!! We will make a 5 x 5 matrix instead Grab some paper and draw this test matrix out!!  Can still manually solve  What would the largest value be for HORIZONTAL and VERTICAL?

9 Using sample Data In main, a 5 by 5 matrix named “twoD” has been created for you!!  Fill the rest of the matrix with values (not done for you) # setup twoD = [0] * ROWS for i in range(ROWS): twoD[i] = [0] * COLS # enter 25 values individually twoD[0][0] = 4

10 Solve the problem Let’s break it down first Easy one first  Multiply horizontally  twoD[0][0] * twoD[0][1] * twoD[0][2] * twoD[0][3]  Store value  Compare with maximum value so far  Then twoD[0][1] * twoD[0][2] * twoD[0][3] * twoD[0][4]  Store value  Compare with maximum value so far  … (in a loop)

11 Solving the problem In thinking it out, what do we have to watch out for??  Initializing a MAX value  Out of bounds  Comparison of the recently multiplied to the CURRENT MAX  Storing the NEW max value

12 Solving the Problem In your lab12.py  The function “multiplyHorizontal()” has been started  Will accept the matrix  Function will return the MAX value it determined  FYI - You will create multiplyVertical() AFTER you are successful with multiplyHorizontal()

13 Write the manual steps as comments Inside your new function  Comment on how you are going to solve it, step by step  Remember, you will need a nested loop, since we are dealing with a matrix  Similar to this: for i in range(ROWS-??): for j in range(COLS-??): answer = …

14 Add code to the comments Begin coding AFTER NEXT slide!!  On your own!! When you think you are done with THAT function  Call the function from main(), while passing your test function # test matrix here maxHorizontal = multiplyHorizontal(twoD) print(maxHorizontal) Make sure your result is correct Move onto multiplyVertical( )

15 What to show your TA Questions about the project inside lab12.py Drawn test matrix Coded  TEST matrix  COMPLETED multiplyHorizontal function  COMPLETED multiplyVertical function Running Code  PRINTED AND CORRECT value from multiplyHorizontal and multiplyVertical function


Download ppt "TA SURVEY Have the TA write their name on the board Fill out the survey at: https://www.surveymonkey.com/s/TAOS_Fall2013 The TA should walk out 5 minutes."

Similar presentations


Ads by Google