Functional Problem Solving (CSC 151 2015S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] - [Calendar]
Current: [Assignment] [EBoard am] [EBoard pm] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards am] [EBoards pm] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2014F)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Book Office Hours] - [Issue Tracker (Course)]
Overview
When will we get homework back?
Next Sunday, if all goes well.
Will you send us an answer key for HW6 because we are sleeping for our health instead of doing the homework for our brain?
Yes. I'll shoot for Sunday.
Will we get our quiz back tomorrow?
I hope so?
Six or seven basic components to an algorithm
when, if, cond)Repetition
map to apply a procedure to each element of a list. Gives you
a list.iota - creates a sequence of numbers, and so is implicitly doing
some repetitionmake-list - create a list of identical valuesimage-variant and image-transform! change all the pixels in an
an image (applying a color transformation), the first creates a new
image, the second changes it in place. Both return imagesimage-compute builds an image by applying a function at each
(x,y) pair.list which calls cons again and again and againIf we restrict ourselves to lists, we don't always want another list of the same size.
iota and make-list, if we wanted to write them ourselves.A common problem solving topic: Decompose a big problem into simpler problems and combine those solutions.
Recursion: Take a large problem and solve a smaller version of the problem.
Counting items in a bag:
Otherwise
Add 1
(define count (lambda (lst) (if (null? lst) 0 (+ 1 (count (cdr lst))))))
Find the heaviest thing in the bag
Otehrwise
Take the heavier of the the item you get back and the item you removed
(heaviest (list 'expo-red 'expo-black 'stapler 'cards 'eraser) 'stapler
(define heaviest (lambda (lst) (if (= (length lst) 1) (car lst) (heavier (car lst) (heaviest (cdr lst))))))
(define largest (lambda (lst) (if (= (length lst) 1) (car lst) (max (car lst) (largest (cdr lst))))))
To find all the red items in the bag
We will continue lab next class.