Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

answer must be in racket kkkkkk************ ;******************************** ; ** problem 2 ** (10 points) ; Write two procedures ; (flip bias) ; (pick lst) ;

answer must be in racket

image text in transcribedimage text in transcribed

kkkkkk************ ;******************************** ; ** problem 2 ** (10 points) ; Write two procedures ; (flip bias) ; (pick lst) ; For each of these procedures you should probably) ; use Racket's random function. ; The procedure (flip bias) simulates flipping a biased coin, ; where the bias is specified as a number between 0 and 1, ; and the result is #t with probability equal to the bias ; and #f with probability (1 - bias). You can test your procedure ; by making sure that 1000 calls to (flip bias) return about ; 1000*bias values of #t. ; The procedure (pick lst) takes a list lst and returns ; a randomly chosen element of Ist. If lst is empty, the ; value returned should be #f. ; You can test it by picking 10000 times from ; a list with 10 elements, and making sure ea element is ; picked about 1000 times. ;; Note: in the test section, we set the random-seed to guarantee ;; the same set of random numbers each time. ; Examples ; (flip .5) => #t ; (flip .5) => #f ; (map (lambda (x) (flip .5)) '(1 2 3 4 5 6 7 8 9 10)) => '(#t #t #t #f #f #f #t #f #f #t) ; (map (lambda (x) (flip .1)) '(1 2 3 4 5 6 7 8 9 10)) => '(#f #f #f #f #f #f #f #f #f #f) ; (map (lambda (x) (flip .2)) '(1 2 3 4 5 6 7 8 9 10)) (#t #f #f #f #f #f #t #f #f #f) ; (map (lambda (x) (flip .2)) '(1 2 3 4 5 6 7 8 9 10)) (#f #f #f #f #f #t #f #f #f #f) ! > ; (pick '(1 2 3 4 5 6 8 9 10) => 8 ; (pick '(1 2 3 4 5 6 8 9 10)) => 10 ; (pick '(1 2 3 4 5 6 8 9 10)) => 3 ; (pick '(1 2 3 4 5 6 8 9 10)) => 2 (define (flip bias) "flip not defined yet" #t) (define (pick lst) "pick not defined yet" 1) ** ****

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions