DOC PREVIEW
Berkeley COMPSCI 61A - Lecture Notes

This preview shows page 1-2-3-4-5-6-7-8-53-54-55-56-57-58-59-107-108-109-110-111-112-113-114 out of 114 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 114 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

61A Lecture 5Wednesday, September 7Wednesday, September 7, 2011Office Hours: You Should Go!You are not alone!2Wednesday, September 7, 2011Office Hours: You Should Go!You are not alone!2Wednesday, September 7, 2011Office Hours: You Should Go!You are not alone!2http://inst.eecs.berkeley.edu/~cs61a/fa11/www/staff.htmlWednesday, September 7, 2011Reminder: Multiple Assignment & Return Values361Aé003éControl_div.py Page 1"""Functions for exact integer division."""from operator import floordiv, moddef divide_exact(n, d): """Return the quotient and remainder of dividing n by d. >>> q, r = divide_exact(13, 5) >>> q 2 >>> r 3 """ return floordiv(n, d), mod(n, d)Wednesday, September 7, 2011Reminder: Multiple Assignment & Return Values361Aé003éControl_div.py Page 1"""Functions for exact integer division."""from operator import floordiv, moddef divide_exact(n, d): """Return the quotient and remainder of dividing n by d. >>> q, r = divide_exact(13, 5) >>> q 2 >>> r 3 """ return floordiv(n, d), mod(n, d)Integer division, which rounds downWednesday, September 7, 2011Reminder: Multiple Assignment & Return Values361Aé003éControl_div.py Page 1"""Functions for exact integer division."""from operator import floordiv, moddef divide_exact(n, d): """Return the quotient and remainder of dividing n by d. >>> q, r = divide_exact(13, 5) >>> q 2 >>> r 3 """ return floordiv(n, d), mod(n, d)Integer division, which rounds downInteger remainderafter dividing Wednesday, September 7, 2011Reminder: Multiple Assignment & Return Values361Aé003éControl_div.py Page 1"""Functions for exact integer division."""from operator import floordiv, moddef divide_exact(n, d): """Return the quotient and remainder of dividing n by d. >>> q, r = divide_exact(13, 5) >>> q 2 >>> r 3 """ return floordiv(n, d), mod(n, d)Multiple return values, separated by commasInteger division, which rounds downInteger remainderafter dividing Wednesday, September 7, 2011Reminder: Multiple Assignment & Return Values361Aé003éControl_div.py Page 1"""Functions for exact integer division."""from operator import floordiv, moddef divide_exact(n, d): """Return the quotient and remainder of dividing n by d. >>> q, r = divide_exact(13, 5) >>> q 2 >>> r 3 """ return floordiv(n, d), mod(n, d)Multiple return values, separated by commasMultiple assignmentto two namesInteger division, which rounds downInteger remainderafter dividing Wednesday, September 7, 2011The Structure of Project 14Two functions implement the game simulationWednesday, September 7, 2011The Structure of Project 14Two functions implement the game simulationWarning!Pseudo-code(not code)Wednesday, September 7, 2011The Structure of Project 14def play(...): while game is not over: get a plan (from the current player's strategy) call take_turn with a dice and plan return winnerTwo functions implement the game simulationWarning!Pseudo-code(not code)Wednesday, September 7, 2011The Structure of Project 14def play(...): while game is not over: get a plan (from the current player's strategy) call take_turn with a dice and plan return winnerdef take_turn(...): while turn is not over: get an action (from plan) and outcome (from dice) call an action return points scored during the turnTwo functions implement the game simulationWarning!Pseudo-code(not code)Wednesday, September 7, 2011The Structure of Project 15Four types of functions are involved in simulating gameDomain RangeWednesday, September 7, 2011The Structure of Project 15Four types of functions are involved in simulating gameDomain RangeAction (integer, integer) (integer, integer, boolean)Wednesday, September 7, 2011The Structure of Project 15Four types of functions are involved in simulating gameDomain RangeAction (integer, integer) (integer, integer, boolean)Two argumentsWednesday, September 7, 2011The Structure of Project 15Four types of functions are involved in simulating gameDomain RangeAction (integer, integer) (integer, integer, boolean)Two arguments Three return valuesWednesday, September 7, 2011The Structure of Project 15Four types of functions are involved in simulating gameDomain RangeAction (integer, integer) (integer, integer, boolean)Planinteger ActionTwo arguments Three return valuesWednesday, September 7, 2011The Structure of Project 15Four types of functions are involved in simulating gameDomain RangeAction (integer, integer) (integer, integer, boolean)Planinteger ActionStrategy(integer, integer) PlanTwo arguments Three return valuesWednesday, September 7, 2011The Structure of Project 15Four types of functions are involved in simulating gameDomain RangeAction (integer, integer) (integer, integer, boolean)Planinteger ActionStrategy(integer, integer) PlanDiceNo arguments integerTwo arguments Three return valuesWednesday, September 7, 2011The Purpose of Higher-Order Functions6Wednesday, September 7, 2011The Purpose of Higher-Order FunctionsFunctions are first-class: Functions can be manipulated as values in our programming language.6Wednesday, September 7, 2011The Purpose of Higher-Order FunctionsFunctions are first-class: Functions can be manipulated as values in our programming language.6Higher-order function: A function that takes a function as an argument value or returns a function as a return valueWednesday, September 7, 2011The Purpose of Higher-Order FunctionsFunctions are first-class: Functions can be manipulated as values in our programming language.6Higher-order functions:Higher-order function: A function that takes a function as an argument value or returns a function as a return valueWednesday, September 7, 2011The Purpose of Higher-Order FunctionsFunctions are first-class: Functions can be manipulated as values in our programming language.6Higher-order functions:• Express general methods of computationHigher-order function: A function that takes a function as an argument value or returns a function as a return valueWednesday, September 7, 2011The Purpose of Higher-Order FunctionsFunctions are first-class: Functions can be manipulated as values in our programming language.6Higher-order functions:• Express general methods of computation•


View Full Document

Berkeley COMPSCI 61A - Lecture Notes

Documents in this Course
Lecture 1

Lecture 1

68 pages

Midterm

Midterm

5 pages

Midterm

Midterm

6 pages

Lecture 35

Lecture 35

250 pages

Lecture 14

Lecture 14

125 pages

Lecture 2

Lecture 2

159 pages

Lecture 6

Lecture 6

113 pages

Lecture 3

Lecture 3

162 pages

Homework

Homework

25 pages

Lecture 13

Lecture 13

117 pages

Lecture 29

Lecture 29

104 pages

Lecture 11

Lecture 11

173 pages

Lecture 7

Lecture 7

104 pages

Midterm

Midterm

6 pages

Midterm

Midterm

6 pages

Lecture 8

Lecture 8

108 pages

Lab 4

Lab 4

4 pages

Lecture 7

Lecture 7

52 pages

Lecture 20

Lecture 20

129 pages

Lecture 15

Lecture 15

132 pages

Lecture 9

Lecture 9

95 pages

Lecture 30

Lecture 30

108 pages

Lecture 17

Lecture 17

106 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?