Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We simulate the rolling of a die. To do this we use the function runif(1) , which returns a 'random' number in the range (0,1).

We simulate the rolling of a die. To do this we use the function runif(1), which returns a 'random' number in the range (0,1). To get a random integer in the range {1,2,3,4,5,6}, we use ceiling(6*runif(1)), or if you prefer, sample(1:6, size=1) will do the same job.

(a) Suppose that you are playing the gambling game of the Chevalier de Mere. That is, you are betting that you get at least one six in 4 throws of a die. Write a program that simulates one round of this game and prints out whether you win or lose.

(b) Turn the program that you wrote in part (a) into a function sixes, which returns TRUE if you obtain at least one six in n rolls of a fair die, and returns FALSE otherwise. That is, the argument is the number of rolls n, and the value returned is TRUE if you get at least one six and FALSE otherwise. How would you give n the default value of 4?

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

Students also viewed these Databases questions