CSC 151.03, Class 24: Randomness and simulation
Overview
- Preliminaries
- Notes and news
- Upcoming work
- Extra credit
- Questions
- Lab
- Debrief
News / Etc.
- More snacks
- Introductory videos
Upcoming Work
- Quiz Friday!
- Recursion
letrec- Named
let
- Writeup for class 23 due TONIGHT at 10:30 p.m.
- Exercises 4d and 5d.
- To: csc151-03-grader@grinnell.edu
- Subject: CSC 151.03 Writeup 23 (YOUR NAMES)
- Writeup for class 24 due Friday at 10:30 p.m.
- Exercises TBD.
- To: csc151-03-grader@grinnell.edu
- Subject: CSC 151.03 Writeup 24 (YOUR NAMES)
- Assignment 6 distributed.
- Although the assignment says that you have assigned pairs, I will permit you to choose your own partners (or to work in individuals or trios).
- Read Pairs for Friday’s class.
Extra credit (Academic/Artistic)
- Saving Brinton, TONIGHT at 7pm in the Strand.
- Gates Lecture, Wednesday at 7:00 p.m. in JRC 101. Professor Sylvester Johnson, Director of the Humanities, Virginia Tech, talk will examine the twentieth-century roots of contemporary national security responses targeting American Muslims as state enemies.
- Convocation Thursday (11 am in JRC 101).
- Random escape room thingy. See signs and advertisements.
- Protest BOT workshop, Friday 4pm in Burling 1st.
Extra credit (Peer)
- Women’s Soccer vs. Cornell today at 4 p.m.
- Advocates Meet and Greet (with ice cream) Thursday 7pm-9pm in JRC 209.
- Submit to the Grinnell Review (grinnellreview.com)
- Pioneer Weekend in about two weeks: A one weekend innovation challenge. Registration at https://grinnell.co1.qualtrics.com/jfe/form/SV_0oKEvGlV5twGczr
Extra credit (Misc)
Other good things
- Grinnell Singers Sunday at 2 p.m. in Sebring Lewis.
- Star Wars Music Talk Friday at 4pm.
- Swimming and Diving meet Saturday.
- SGA hosts tailgate at 11:30 on Saturday near the grassy knoll.
- Football Saturday.
Questions
Lab
Problem one should look something like the following
(define count-odd-rolls
(lambda (n)
(cond
[(zero? n)
0]
[(odd? (roll-a-die))
...]
[else
...])))
There are two primary approaches to problem 2, which has the problem of evaluating the same expression twice. (That’s usually bad. In this case, it breaks the program.)
- You could use a
letto name the result of the expression. That turns out to be more subtle than you might expect. - You could write a procedure,
seven-or-eleven?that, given an integer input, returns#texactly when that input is 7 or 11.
Hints on 6
6a: Use map and reduce.
6b: Generate a random number between 0 and 100, inclusive, then check if it’s less than 24, less than 38, …
6c: You should know a pattern for generating lists of values.
6d: No additional help should be necessary.
Debrief
Yes, it is intentional that we’ve asked you to look at two different forms of tallying.
Reminder: Your notes should probably have “Ways to tally” and “Ways to generate lists recursively” and other patterns you’ve been observing.
(define tally-odd
(lambda (n)
(cond
[(zero? n)
0]
[(odd? (roll-a-die))
(+ 1 (tally-odd (- n 1)))]
[else
(tally-odd (- n 1))])))
This can be translated fairly straightforwardly to the following.
(define seven-or-eleven?
(lambda (val)
(or (= val 7) (= val 11))))
(define tally-7-11
(lambda (n)
(cond
[(zero? n)
0]
[(seven-or-eleven? (pair-a-dice))
(+ 1 (tally-7-11 (- n 1)))]
[else
(tally-7-11 (- n 1))])))