Warning! You are being recorded and transcribed, provided the technology is working correctly.
Approximate optimistic overview
Scholarly
Artistic
Multicultural
Peer
Musical, theatric, sporting, and academic events involving this section’s students are welcome.
Wellness
Misc
These do not earn tokens, but are worth your consideration.
We’re skipping recursion questions for now.
When can I make up the Documentation LA?
On SoLA 2. (or SoLAs 3, 4, or 5)
Suppose I don’t do well on the lists LA. When can I make that up?
On SoLA 2. (or SoLAs 3, 4, or 5)
I’m struggling with how to get part 2 to work. Any hints?
You’ll need to use some of the same ideas as in part 1. In particular, you’ll find it helpful to write a helper procedure that checks whether its parameter is a shape or not and does different things based on that test.
This also applies for part 3.
The autograder is borken.
I’ll work on fixing that today.
On the freestyle, how many procedures should we write?
I’d prefer that you write at least four procedures.
One will mimic part one. (Also helpers.)
One will mimic part two. (Also helpers.)
One will mimic part three. (Also helpers.)
One will tie everything together.
I have a complicated private question. Should I ask it in class?
You can Teams Message me.
if the input is simple enough to solve directly
solve it directly
otherwise
make the input a little bit smaller
solve the problem with the smaller input USING EXACTLY THE SAME
PROCESS
update that solution with the element (or elements) we removed to
make the input smaller.
There’s a magic recusion fairy who makes this work.
if there's nothing left in the stack of cards
we have zero cards
otherwise
remove one card
ask the same question of your assistant (the input is smaller so we
meet UGSDW regulations)
add 1 and return the result
We’ve written length
.
if there's nothing left in the stack
return 0
otherwise
remove one card
ask the same question of your assistant
if you have the same number of 1's and 0's on that removed card
add 1 to the result you got from your assistant
otherwise
just pass along the result you got from your assistant.
We’ve written tally
.
if there's nothing left in the stack
return nothing
otherwise
remove one
ask your assistant to do the same task
if your card is a consonant
add that card to what you got from your assistant and return the
modified stack
otherwise
pass along what your assistant gave you
We’ve written: filter
Things we need to think about
(define my-length
(lambda (lst)
(if (null? lst)
0
(+ 1 (my-length (cdr lst))))))
We got it right on the first try!
Note: If we don’t simplify the parameter, we’ll like get a giant error box and our computer might catch on fire.
(define tally-odds
(lambda (lst)
(if (null? lst)
0
(if (odd? (car lst))
(+ 1 (tally-odds (cdr lst)))
(+ 0 (tally-odds (cdr lst)))))))
We got it right on the first try! (but with a bit of prompting)
But … adding zero is pointless.
(define tally-odds
(lambda (lst)
(if (null? lst)
0
(if (odd? (car lst))
(+ 1 (tally-odds (cdr lst)))
(tally-odds (cdr lst))))))
But … nested ifs should be replaced by conds.
(define tally-odds
(lambda (lst)
(cond
[(null? lst)
0]
[(odd? (car lst))
(+ 1 (tally-odds (cdr lst)))]
[else
(tally-odds (cdr lst))])))
(define select-evens
(lambda (lst)
(cond
[(null? lst)
null]
[(even? (car lst))
(cons (car lst) (select-evens (cdr lst)))]
[else
(select-evens (cdr lst))])))
At the beginning of the semester, we said that we had to know how to do six tings in order to write algorithms. What were they? And what have we learned about them in Scheme?