Exercises
The following exercises provide you with the opportunity to practice with Monte Carlo algorithms. The solutions to these exercises are found in the section Chapter 9.
-
Say that we have a large array of integers, and we want to determine what percentage of the integers are even and what percentage are odd. Write code that performs random sampling to approximate these percentages.
-
Let’s say that I ran The Formula from Fermat’s Primality Test on an integer N a total of four times. Three times the result was 1, and one time the result was 2. What are the odds that N is prime?
-
Now, let’s say that I ran The Formula from Fermat’s Primality Test on an integer N a total of four times, and all four times the result was 1. What are the odds ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access