Cs1120 Fall 2009 David Evans http://www.cs.virginia.edu/cs1120 Lecture 10: Fracturing Fractals cs1120 Fall 2009 David Evans http://www.cs.virginia.edu/cs1120.

Slides:



Advertisements
Similar presentations
Cs1120 Fall 2009 David Evans Lecture 11: Generalizing List Procedures 1.
Advertisements

Class 6: Programming with Data David Evans cs1120 Fall 2009.
Class 21: Imperative Programming University of Virginia cs1120 David Evans.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 13: Of On and Off Grounds Sorting.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Cs1120 Fall 2009 David Evans Lecture 15: Running Practice.
Cs1120 Fall 2009 David Evans Lecture 16: Power Analysis.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 18: The Story So Far.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 16: Quicker Sorting.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 40: Computing with Glue and Photons.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 14: Asymptotic Growth.
David Evans cs302: Theory of Computation University of Virginia Computer Science Lecture 2: Modeling Computers.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 11: 1% Pure Luck Make-up lab hours:
Cs1120 Fall 2009 David Evans Lecture 20: Programming with State.
Cs1120 Fall 2009 David Evans Lecture 19: Stateful Evaluation.
David Evans Class 12: Quickest Sorting CS150: Computer Science University of Virginia Computer Science Rose Bush by Jacintha.
David Evans Class 13: Quicksort, Problems and Procedures CS150: Computer Science University of Virginia Computer Science.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 11: CS Logo, by Lincoln Hamilton and.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Think Globally, Mutate Locally.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
David Evans CS200: Computer Science University of Virginia Computer Science Class 17: Mutation M. C. Escher, Day and Night.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 10: Puzzling Pegboards.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 9: Strange Loops and Sinister Repeaters.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 3: Levels of Abstraction
Abstraction: Procedures as Parameters CMSC Introduction to Computer Programming October 14, 2002.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 36: Modeling Computing.
Class 8: Recursing on Lists David Evans cs1120 Fall 2009.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 12: QuickSorting Queen’s University,
David Evans CS200: Computer Science University of Virginia Computer Science Class 16: Mutation M. C. Escher, Day and Night.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 19: Environments.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 5: Recursing on Lists.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 9: Of On and Off Grounds Sorting Coffee.
Class 29: Charme School cs1120 Fall 2009 University of Virginia David Evans.
David Evans Class 15: P vs. NP (Smiley Puzzles and Curing Cancer) CS150: Computer Science University of Virginia Computer.
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 8: Crash Course in Computational Complexity.
Class 7: List Procedures David Evans cs1120 Fall 2009.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 14: P = NP?
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 4: Programming with Data.
David Evans CS150: Computer Science University of Virginia Computer Science Class 32: Computability in Theory and Practice.
Lecture 4: Metacircles Eval Apply David Evans
Class 8: Procedure Practice
Lecture 4: Evaluation Rules Recursion CS200: Computer Science
Lecture 13: Quicksorting CS200: Computer Science
Class 30: Models of Computation CS200: Computer Science
Lecture 7: List Recursion CS200: Computer Science
Lecture 37: A Universal Computer
6.001 SICP Data abstractions
Lecture 8: Recursion Practice CS200: Computer Science
Lecture 16: Quickest Sorting CS150: Computer Science
Lecture 6: Programming with Data CS150: Computer Science
Lecture 11: All Sorts CS200: Computer Science University of Virginia
David Evans Lecture 9: The Great Lambda Tree of Infinite Knowledge and Ultimate Power CS200: Computer Science University.
Lecture 28: Types of Types
Lecture 13: Cost of Sorts CS150: Computer Science
Lecture 25: Metalinguistics > (meval '((lambda (x) (* x x)) 4)
Lecture 22: P = NP? CS200: Computer Science University of Virginia
Lecture 10: Quicker Sorting CS150: Computer Science
Lecture 26: The Metacircular Evaluator Eval Apply
Lecture 9: The Great Lambda Tree of Knowledge and Power
Class 34: Models of Computation CS200: Computer Science
Class 33: Learning to Count CS200: Computer Science
Lecture 3: Rules of Evaluation CS200: Computer Science
Class 26: Modeling Computing CS150: Computer Science
Lecture 15: Quicker Sorting CS150: Computer Science
Lecture 11: Sorting Grounds and Bubbles
CS 403: Programming Languages
Lecture 8: Recursing Lists CS150: Computer Science
Lecture 25: The Metacircular Evaluator Eval Apply
Presentation transcript:

cs1120 Fall 2009 David Evans http://www.cs.virginia.edu/cs1120 Lecture 10: Fracturing Fractals cs1120 Fall 2009 David Evans http://www.cs.virginia.edu/cs1120

Menu Problem Set 2 Mapping Lists Problem Set 3

Problem Sets Not just meant to review stuff you should already know Get you to explore new ideas Motivate what is coming up in the class The main point of the PSs is learning, not evaluation Don’t give up if you can’t find the answer in the book (you won’t solve many problems this way) Do discuss with other students Do get help from Help Hours and Office Hours

PS2: Question 3 Why is (define (higher-card? card1 card2) (> (card-rank card1) (card-rank card2) better than (> (car card1) (car card2)) ? Data Abstraction: to understand more complex programs, we need to hide details about how data is represented and think about what we do with it.

PS2: Question 8, 9 Predict how long it will take Identify ways to make it faster Most of next week and much of many later classes will be focused on how computer scientists predict how long programs will take, and on how to make them faster.

Question 7 (“Gold Star” answer) (define (find-best-hand hole-cards community-cards) (car (sort (possible-hands hole-cards community-cards)) higher-hand?)) How can we do better?

Hmmm.... (define (pick-minimizer f a b) (if (< (cf a) (cf b)) a b)) from last class: (define (pick-minimizer f a b) (if (< (cf a) (cf b)) a b)) (define (find-minimizer f p) (if (null? (cdr p)) (car p) (pick-minimizer f (car p) (find-minimizer f (cdr p)))))

find-best (define (find-best f p) (if (null? (cdr p)) (car p) (pick-best f (find-best f (cdr p))))) (define (pick-best f a b) (if (f a b) a b))

Next week: how much better is this? find-best-hand (define (find-best-hand hole-cards community-cards) (find-bestiest (possible-hands hole-cards community-cards)) higher-hand?)) Next week: how much better is this?

Mapping Lists Define a procedure list-map that takes two inputs, a procedure and a list and produces as output a list whose elements are the results of applying the input procedure to each element in the input list. (Example 5.4) > (list-map square (list 1 2 3)) (1 4 9) > (list-map (lambda (x) (* x 2)) (list 1 2 3 4)) (2 4 6 8) > (list-map (lambda (x) (if (odd? x) (+ x 1))) (list 1 2 3 4)) (2 2 4 4)

list-map (define (list-map f p) (if (null? p) null (cons (f (car p)) (list-map f (cdr p))))) Equivalent to the built-in procedure map (except map can work on more than one list).

Charge Don’t leave yet: will return PS2 and Quiz next PS3 is due in one week Help Hours tonight (6-8:30pm in Olsson 001) Extra office hours tomorrow, 11am-noon I’ll be away next week – lectures by Wes Weimer!

Returning PS2 and Quiz abc8a … dwa2x eab8d … jsw8a jta9nk … mz2h Front abc8a … dwa2x eab8d … jsw8a jta9nk … mz2h os9e … wch9a