This class will be recorded! Its use is limited to members of the class. Please do not share with others.
Approximate overview
Attend (or watch recording) and send a one-paragraph reflection.
Click on the day’s title in the schedule.
Go to the Handouts page and scroll to the bottom for the list.
Memorize the form of the URLs.
How does the twenty-minutes / twenty-four hour thing work?
Once you open a question, you have twenty minutes to solve it.
You can choose when to open each question and in what order to do so. (E.g., you can start with tracing rather than decomposition, even though decomposition is the first listed learning objective.)
The Learning Assessments page tells you what each is about (broadly).
I’m too lazy to look at yesterday’s eboard. Can you remind me about how I might decide whether a string contains only digits?
Sure. Use
string->number. That will only succeed if the string can be converted to a number. Make sure that it’s an integer (no decimals, no imaginary). Make sure that it’s positive.
Is there a way to run a predicate on a list?
Yes. (I’ll mention it at the start of class. It will also be in tonight’s reading.)
(all pred? lst)holds only when the predicate holds for all elements of the list.
(any pred? lst)holds only when the predicate holds for at least one element of the list.
If I know that “123456789X” is valid, how do I know that “123456780X” cannot be valid?
Because the formula for computing check digits ensures that any one digit switch leads to a failure in checking. (or it should)
I did not understand the check thing.
Suppose I want to ensure that all procedures return “SamR”.
I’m going to write a procedure
(check-samr val)which returns #t if val is “SamR” and raise an error otherwise. (Your goal is to write a generalized of this.)
Then I put some
(check-samr ...)calls after my procedure to ensure that it works correctly. When I click “Run”, I’ll either see a bunch of#ts or some red text. If I see red text, I know that something’s wrong.
You’re going to put a bunch of
(check-equals ...)calls at the end of your definitions.
(check-equals #t (valid-isbn? "123456789X"))
(check-equals #f (valid-isbn? "123456780X"))
How do I compute “10×1 + 9×2 + 8×3 + 7×4 + 6×5 + 5×6 + 4×7 + 3×8 + 2×9”? I think I can use two lists.
Two lists is a great idea.
For
'(10 9 8 7 6 5 4 3 2), I’d userange.
We can use
mapto multiply the lists.
Can I see the sample code you wrote?
; Definitions pane
(define multipliers (list 10 9 8 7 6 5 4 3 2))
(define digits (list 1 2 3 4 5 6 7 8 9))
; Intereactions pane
> (map * multipliers digits)
'(10 18 24 28 30 30 28 24 18)
How do I go from a string to a list of numbers?
string->listis a good first step, but you’ll need to do more, since that gives you a list of characters.