05-Jan-2023 17:00:43 digital_dice_test(): MATLAB/Octave version 9.8.0.1380330 (R2020a) Update 2 Test digital_dice(). aandb(): In game A, you flip a biased coin, which shows heads with probabiity] 1/2 - epsilon; you win a dollar on heads. In game B, you have two biased coins. If, at the time just before you decide to flip, your capital M is a multiple of 3 dollars, you chose coin 1, which shows heads with probability 1/10 - epsilon, otherwise you choose coin 2, which shows heads with probability 3/4 - epsilon. Both games A and B are losing games for you. But, paradoxically, if you randomly switch back and forth between one game and the other, you end up winning over the long term. Use graphics to display the winnings. Graphics saved as "aandb.png" average(): Use a Monte Carlo sample to estimate pi. Estimate for pi = 3.25381 Error = -0.112219 Antithetic estimate for pi = 3.09509 Error = 0.046502 average(): Use a Monte Carlo sample to estimate pi. Estimate for pi = 3.13568 Error = 0.00591519 Antithetic estimate for pi = 3.1412 Error = 0.000393039 average(): Use a Monte Carlo sample to estimate pi. Estimate for pi = 3.14242 Error = -0.000824013 Antithetic estimate for pi = 3.14162 Error = -3.00045e-05 baby_boom(): There are given probabilities of a man having 0, 1, 2, 3, 4, 5, 6 or 7 sons. What are the chances of having: 2 sons in the second generation? 4 sons in the second generation? 6 sons in the third generation? Estimated probabilities: 2 males in generation 2 = 0.0708 4 males in generation 2 = 0.0423 6 males in generation 3 = 0.0203 baby_boom(): There are given probabilities of a man having 0, 1, 2, 3, 4, 5, 6 or 7 sons. What are the chances of having: 2 sons in the second generation? 4 sons in the second generation? 6 sons in the third generation? Estimated probabilities: 2 males in generation 2 = 0.06732 4 males in generation 2 = 0.03964 6 males in generation 3 = 0.02076 broke(): Three players begin with L, M and N dollars. On each turn, each player flips a coin. All coins have the same bias P = 0.5 If one player is "odd man out", he pays a dollar to each other player. When a player is bankrupt, the game is over. What is the average number of turns required? Average number of turns = 1.33487 broke(): Three players begin with L, M and N dollars. On each turn, each player flips a coin. All coins have the same bias P = 0.5 If one player is "odd man out", he pays a dollar to each other player. When a player is bankrupt, the game is over. What is the average number of turns required? Average number of turns = 1.99497 broke(): Three players begin with L, M and N dollars. On each turn, each player flips a coin. All coins have the same bias P = 0.5 If one player is "odd man out", he pays a dollar to each other player. When a player is bankrupt, the game is over. What is the average number of turns required? Average number of turns = 4.58118 broke(): Three players begin with L, M and N dollars. On each turn, each player flips a coin. All coins have the same bias P = 0.5 If one player is "odd man out", he pays a dollar to each other player. When a player is bankrupt, the game is over. What is the average number of turns required? Average number of turns = 5.15229 broke(): Three players begin with L, M and N dollars. On each turn, each player flips a coin. All coins have the same bias P = 0.5 If one player is "odd man out", he pays a dollar to each other player. When a player is bankrupt, the game is over. What is the average number of turns required? Average number of turns = 18.589 broke(): Three players begin with L, M and N dollars. On each turn, each player flips a coin. All coins have the same bias P = 0.4 If one player is "odd man out", he pays a dollar to each other player. When a player is bankrupt, the game is over. What is the average number of turns required? Average number of turns = 1.3859 broke(): Three players begin with L, M and N dollars. On each turn, each player flips a coin. All coins have the same bias P = 0.4 If one player is "odd man out", he pays a dollar to each other player. When a player is bankrupt, the game is over. What is the average number of turns required? Average number of turns = 2.08157 broke(): Three players begin with L, M and N dollars. On each turn, each player flips a coin. All coins have the same bias P = 0.4 If one player is "odd man out", he pays a dollar to each other player. When a player is bankrupt, the game is over. What is the average number of turns required? Average number of turns = 4.75358 broke(): Three players begin with L, M and N dollars. On each turn, each player flips a coin. All coins have the same bias P = 0.4 If one player is "odd man out", he pays a dollar to each other player. When a player is bankrupt, the game is over. What is the average number of turns required? Average number of turns = 5.3724 broke(): Three players begin with L, M and N dollars. On each turn, each player flips a coin. All coins have the same bias P = 0.4 If one player is "odd man out", he pays a dollar to each other player. When a player is bankrupt, the game is over. What is the average number of turns required? Average number of turns = 19.4407 bus(): 1 bus lines are available at a bus stop. In any hour, each bus line will come to the stop at a random time. A passenger arrives at the bus stop at a random time. What is the average wait for a bus? Estimated waiting time = 0.499813 Theoretical time = 0.5 bus(): 2 bus lines are available at a bus stop. In any hour, each bus line will come to the stop at a random time. A passenger arrives at the bus stop at a random time. What is the average wait for a bus? Estimated waiting time = 0.333143 Theoretical time = 0.333333 bus(): 3 bus lines are available at a bus stop. In any hour, each bus line will come to the stop at a random time. A passenger arrives at the bus stop at a random time. What is the average wait for a bus? Estimated waiting time = 0.250208 Theoretical time = 0.25 bus(): 4 bus lines are available at a bus stop. In any hour, each bus line will come to the stop at a random time. A passenger arrives at the bus stop at a random time. What is the average wait for a bus? Estimated waiting time = 0.19995 Theoretical time = 0.2 bus(): 5 bus lines are available at a bus stop. In any hour, each bus line will come to the stop at a random time. A passenger arrives at the bus stop at a random time. What is the average wait for a bus? Estimated waiting time = 0.166647 Theoretical time = 0.166667 car(): Park 3 cars in a line, and compute each car's nearest neighbor Estimate the probability that a given car is the nearest neighbor of its nearest neighbor. Estimated probability = 0.666667 Theoretical probability is 0.666667 car(): Park 10 cars in a line, and compute each car's nearest neighbor Estimate the probability that a given car is the nearest neighbor of its nearest neighbor. Estimated probability = 0.666675 Theoretical probability is 0.666667 car(): Park 20 cars in a line, and compute each car's nearest neighbor Estimate the probability that a given car is the nearest neighbor of its nearest neighbor. Estimated probability = 0.666727 Theoretical probability is 0.666667 car(): Park 30 cars in a line, and compute each car's nearest neighbor Estimate the probability that a given car is the nearest neighbor of its nearest neighbor. Estimated probability = 0.666598 Theoretical probability is 0.666667 chess(): A has to play three games of chess against B and C. A beats B with probability P, C with probability Q A has a choice of schedules: BCB or CBC. To win the tournament, A must win two successive games. Which schedule is better? Estimated win probability for BCB is = 0.792118 Estimated win probability for CBC is = 0.863938 chess(): A has to play three games of chess against B and C. A beats B with probability P, C with probability Q A has a choice of schedules: BCB or CBC. To win the tournament, A must win two successive games. Which schedule is better? Estimated win probability for BCB is = 0.395898 Estimated win probability for CBC is = 0.575968 chess(): A has to play three games of chess against B and C. A beats B with probability P, C with probability Q A has a choice of schedules: BCB or CBC. To win the tournament, A must win two successive games. Which schedule is better? Estimated win probability for BCB is = 0.192196 Estimated win probability for CBC is = 0.203954 chess(): A has to play three games of chess against B and C. A beats B with probability P, C with probability Q A has a choice of schedules: BCB or CBC. To win the tournament, A must win two successive games. Which schedule is better? Estimated win probability for BCB is = 0.064142 Estimated win probability for CBC is = 0.07623 committee(): From a faculty of 6 professors, 6 associate professors, 10 assistant professors, and 12 instructors, a committee of size 6 is formed randomly. What is the probablity that there is at least one person of each rank in the committee? Estimated probability = 0.37798 Exact probablity = 0.379031 deli(): A deli is open for 36,000 seconds. There are 1 or 2 clerks. Customers arrive at random. The amount of time it takes to service a customer is random. Customers are served in order. A clerk serves one customer at a time. Newly arrived customers wait in a queue if no clerk is available. What is the average and maximal times spent per customer? What is the average and maximal queue length? What percentage of time are the clerks idle? Average total time at deli 1014.34 Maximum time at deli 3222 Average queue length 8.59247 Maximum queue length 29 Percent idle time clerk1 6.58889 Percent idle time clerk2 0 deli(): A deli is open for 36,000 seconds. There are 1 or 2 clerks. Customers arrive at random. The amount of time it takes to service a customer is random. Customers are served in order. A clerk serves one customer at a time. Newly arrived customers wait in a queue if no clerk is available. What is the average and maximal times spent per customer? What is the average and maximal queue length? What percentage of time are the clerks idle? Average total time at deli 109.185 Maximum time at deli 573 Average queue length 0.117722 Maximum queue length 3 Percent idle time clerk1 52.3194 Percent idle time clerk2 75.1222 deli(): A deli is open for 36,000 seconds. There are 1 or 2 clerks. Customers arrive at random. The amount of time it takes to service a customer is random. Customers are served in order. A clerk serves one customer at a time. Newly arrived customers wait in a queue if no clerk is available. What is the average and maximal times spent per customer? What is the average and maximal queue length? What percentage of time are the clerks idle? Average total time at deli 9655 Maximum time at deli 19882 Average queue length 136.906 Maximum queue length 264 Percent idle time clerk1 0.125 Percent idle time clerk2 0 deli(): A deli is open for 36,000 seconds. There are 1 or 2 clerks. Customers arrive at random. The amount of time it takes to service a customer is random. Customers are served in order. A clerk serves one customer at a time. Newly arrived customers wait in a queue if no clerk is available. What is the average and maximal times spent per customer? What is the average and maximal queue length? What percentage of time are the clerks idle? Average total time at deli 1004.51 Maximum time at deli 2465 Average queue length 11.5885 Maximum queue length 29 Percent idle time clerk1 3.825 Percent idle time clerk2 3.92222 dinner(): N guests sit down at a dinner table, without noticing the name tags. What are the chances that no one sits at their assigned seat? N P(derangement) 1 0 2 0.5 3 0.3333333333333333 4 0.375 5 0.3666666666666667 6 0.3680555555555556 7 0.3678571428571428 8 0.3678819444444444 9 0.367879188712522 10 0.3678794642857143 11 0.3678794392336059 12 0.3678794413212816 13 0.3678794411606912 14 0.3678794411721619 15 0.3678794411713971 16 0.367879441171445 17 0.3678794411714422 18 0.3678794411714424 19 0.3678794411714424 20 0.3678794411714423 dish(): Five dishwashers work together. Five dishes are broken. What are the chances that at least four of the dishes are broken by the same particular dishwasher? Probability dishwasher #1 breaks at least 4 out of 5 dishes = 0.006734 Theoretical probability is 0.00672 easywalk(): A pedestrian begins 1000 blocks east and 1000 blocks north of a destination. At each intersection, there is a stop light which is set randomly, and switches after 1 minute. Until reaching avenue 1 or street 1, the pedestrian always crosses the intersection in accordance with the stop light. Thereafter, the pedestrian must wait at each stop light encountered. What is the exact expected wait for stop lights? Use graphics to display the expected results. Graphics saved as "easywalk.png" election(): N voters participate in an election. n of the voters are candidates. Voting rules may allow a voter to vote for themselves, or not. M votes are required in order for a leader to be chosen. What is the probability that, on a single vote, a leader will be chosen? Probability a leader was selected = 1 election(): N voters participate in an election. n of the voters are candidates. Voting rules may allow a voter to vote for themselves, or not. M votes are required in order for a leader to be chosen. What is the probability that, on a single vote, a leader will be chosen? Probability a leader was selected = 0.77908 election(): N voters participate in an election. n of the voters are candidates. Voting rules may allow a voter to vote for themselves, or not. M votes are required in order for a leader to be chosen. What is the probability that, on a single vote, a leader will be chosen? Probability a leader was selected = 0.0604 election(): N voters participate in an election. n of the voters are candidates. Voting rules may allow a voter to vote for themselves, or not. M votes are required in order for a leader to be chosen. What is the probability that, on a single vote, a leader will be chosen? Probability a leader was selected = 0.10682 estimate(): N runners participate in a marathon. Each runner wears a tag with their index, from 1 to N. We observe the values of K of these tags. We want to estimate N. Produce illustrative plots for several cases. Graphics saved as "estimate.png" floss(): A person buys two rolls of dental floss. Each roll has 40 feet of floss. The person randomly selects a roll and takes 1 foot of floss. When one roll runs out, how many feet remain in the other roll? Average remaining floss = 7.11423 floss(): A person buys two rolls of dental floss. Each roll has 150 feet of floss. The person randomly selects a roll and takes 1 foot of floss. When one roll runs out, how many feet remain in the other roll? Average remaining floss = 13.8083 forgetful_burglar(): In a town of 201 homes, a burglar starts at home 101. He randomly moves one or two homes left or right. What is the typical number of moves he will make before revisiting a home? K Prob(K) 1 0 2 0.250171 3 0.281204 4 0.195319 5 0.117215 6 0.0683627 7 0.0388426 8 0.0217806 9 0.0121527 10 0.0066848 Graphics saved as "fb.png" gameb(): In game B, you have two biased coins. If, at the time just before you decide to flip, your capital M is a multiple of 3 dollars, you chose coin 1, which shows heads with probability 1/10 - epsilon, otherwise you choose coin 2, which shows heads with probability 3/4 - epsilon. Game B is a losing game for you, and this code simply demonstrates that using many simulations. Produce a plot showing how the player loses. Graphics saved as "gameb.png" gs(): A building has 7 floors, and there are n elevators, each of which is at a randomly chosen floor. A person on floor 2 requests an elevator, wishing to go up. What is the probability that the first elevator to arrive is going down? Estimated probability of down elevator = 0.833097 Theoretical probability is 0.833333 gs(): A building has 7 floors, and there are n elevators, each of which is at a randomly chosen floor. A person on floor 2 requests an elevator, wishing to go up. What is the probability that the first elevator to arrive is going down? Estimated probability of down elevator = 0.722038 Theoretical probability is 0.722222 gs(): A building has 7 floors, and there are n elevators, each of which is at a randomly chosen floor. A person on floor 2 requests an elevator, wishing to go up. What is the probability that the first elevator to arrive is going down? Estimated probability of down elevator = 0.647621 Theoretical probability is 0.648148 guess(): Given M items of ranks 1 through M, randomly guess the rank of each item. On average, how many ranks will we guess correctly? Average number of correct pairings = 1.0005 Expected value is 1. jury(): There are 5 judges on an appeals court. Each judge has a probability of making a correct ruling. What is the probability that a majority of the judges will rule incorrectly? Probability of a mistaken judgement = 0.0070078 kelvin(): A biased coin comes up heads with probability 0.4. To get a unbiased random value, toss the coin twice. If you get TH, call it heads; if you get HT, call it tails. If you get TT or HH, do another double toss. On average, how many double tosses are necessary? Average number of double tosses = 2.0761 Theoretical value = 2.08333 malt(): Lil and Bill agree to meet in the malt shop between 3:30 and 4:00. Each arrives at a random time. Lil will wait 5 minutes, then leave. Bill will wait 7 minutes, then leave. What is the probability of a meeting? Estimated meeting probability = 0.358859 Theoretical probability is 0.358889 missing(): There are 100 senators. A bill needs a majority of present senators to pass. A senators are against the bill. M senators are missing the vote. What is the probability that the bill will be defeated? Probability of defeat = 0.128476 missing(): There are 100 senators. A bill needs a majority of present senators to pass. A senators are against the bill. M senators are missing the vote. What is the probability that the bill will be defeated? Probability of defeat = 0.063577 missing(): There are 100 senators. A bill needs a majority of present senators to pass. A senators are against the bill. M senators are missing the vote. What is the probability that the bill will be defeated? Probability of defeat = 0.193682 mono(): Expected value of the number of random numbers that can be generated, which are monotone increasing. Extimated expected length = 2.71805 Expected value is 2.71828. obtuse(): Define a "random" triangle as half of a rectangle with height 1 and width 1 <= L. What are the chances the triangle is obtuse? Using value L = 1 Estimated likelihoood of obtuse triangle = 0.725212 For L=1, expected value = 0.725206 For L=2, expected value = 0.798374 obtuse1(): Define a "random" triangle by splitting the unit interval into three random pieces. What are the chances the triangle is obtuse? Estimated likelihoood of obtuse triangle = 0.17034 Exact value is 0.170558 optimal(): A dating club offers 11 potential partners. It turns out that any of 2 of these partners would be acceptable. The dater gets 1 date with each partner, but immediately after the date, must either marry that partner, or move to the next date. The dater plans to date a sample of the partners without a marriage offer, and then marry the next partner who is better than all the sample dates. As the sample size is varied, what are the chances of happiness? Use graphics to display result. Graphics saved as "optimal.png" optimal(): A dating club offers 50 potential partners. It turns out that any of 5 of these partners would be acceptable. The dater gets 1 date with each partner, but immediately after the date, must either marry that partner, or move to the next date. The dater plans to date a sample of the partners without a marriage offer, and then marry the next partner who is better than all the sample dates. As the sample size is varied, what are the chances of happiness? Use graphics to display result. Graphics saved as "optimal.png" patrol(): Consider a divided highway, and suppose it could be divided by a grassy median or a concrete barrier. Suppose NUMBER police cars patrol the highway. Suppose an accident occurs at a randomly chosen location and lane. Suppose all patrol cars immediately head towards the accident. If a grassy median, then patrol cars in the wrong lane can immediately reverse direction. For the concrete barrier, patrol cars in the wrong lane must continue to the end of the highway and then turn around. Estimate the average time required by a patrol car to reach the accident. Average grass distance = 0.333548 Average concrete distance = 0.999518 patrol(): Consider a divided highway, and suppose it could be divided by a grassy median or a concrete barrier. Suppose NUMBER police cars patrol the highway. Suppose an accident occurs at a randomly chosen location and lane. Suppose all patrol cars immediately head towards the accident. If a grassy median, then patrol cars in the wrong lane can immediately reverse direction. For the concrete barrier, patrol cars in the wrong lane must continue to the end of the highway and then turn around. Estimate the average time required by a patrol car to reach the accident. Average grass distance = 0.208144 Average concrete distance = 0.666751 patrol(): Consider a divided highway, and suppose it could be divided by a grassy median or a concrete barrier. Suppose NUMBER police cars patrol the highway. Suppose an accident occurs at a randomly chosen location and lane. Suppose all patrol cars immediately head towards the accident. If a grassy median, then patrol cars in the wrong lane can immediately reverse direction. For the concrete barrier, patrol cars in the wrong lane must continue to the end of the highway and then turn around. Estimate the average time required by a patrol car to reach the accident. Average grass distance = 0.149825 Average concrete distance = 0.500455 patrol(): Consider a divided highway, and suppose it could be divided by a grassy median or a concrete barrier. Suppose NUMBER police cars patrol the highway. Suppose an accident occurs at a randomly chosen location and lane. Suppose all patrol cars immediately head towards the accident. If a grassy median, then patrol cars in the wrong lane can immediately reverse direction. For the concrete barrier, patrol cars in the wrong lane must continue to the end of the highway and then turn around. Estimate the average time required by a patrol car to reach the accident. Average grass distance = 0.116791 Average concrete distance = 0.399881 patrol(): Consider a divided highway, and suppose it could be divided by a grassy median or a concrete barrier. Suppose NUMBER police cars patrol the highway. Suppose an accident occurs at a randomly chosen location and lane. Suppose all patrol cars immediately head towards the accident. If a grassy median, then patrol cars in the wrong lane can immediately reverse direction. For the concrete barrier, patrol cars in the wrong lane must continue to the end of the highway and then turn around. Estimate the average time required by a patrol car to reach the accident. Average grass distance = 0.095128 Average concrete distance = 0.333222 pierror(): Estimate pi by counting random points in the unit square which are also in the quarter circle. Using 100 points, estimate is 0.89, absolute error 2.25159 pierror(): Estimate pi by counting random points in the unit square which are also in the quarter circle. Using 10000 points, estimate is 0.7819, absolute error 2.35969 ranking(): A list of 24 items is given. The test taker is required to give a rank for each. For each item, the test taker randomly chooses a value between 1 and M. What is the average number of correct rankings? Average number of correct matches = 0.998299 rhs(): Random Harmonic Series: Compute and histogram many values of the partial sums of sum ( 1 <= k < infinity ) t(i) / k where t(i) is randomly +1 or -1. Graphics saved as "rhs.png" rolls(): Two rolls of toilet paper are installed in a toilet, with 200 sheets. There are two kinds of people, with probabilities p and 1-p. * big choosers take one sheet from the larger roll; * little choosers take one sheet from the smaller roll (unless empty). When one roll becomes empty, how many sheets are on the other roll? Use graphics to display results. Graphics saved as "rolls.png" smoker(): A smoker buys two packs of 40 matches. He then repeatedly selects a match from a randomly chosen pack. When one pack runs out, how many matches have been used in total? Average total number of matches used = 72.886 Graphics saved as "smoker.png" smokerb(): A smoker buys two packs of 40 matches. He then repeatedly selects a match from a randomly chosen pack. At some point, the pack he chooses will be empty. How many matches have been used by then? Average total number of matches used = 73.795 Graphics saved as "smokerb.png" spin(): A game involves two spinnable disks, each divided into three sectors. A player spins disk 1 or 2 according to the following rules: * if the player spins disk i, and it stops in region Pij, he moves from disk i to disk j; * if the spinner stops in region Pi3, the game ends. * if the game ends in P13, the player wins. What is the probablity that the player, starting with disk 1, wins? Probabiity of winning = 0.6596 Theoretical value = 0.65 steve(): Steve gets on an elevator going up. There are 11 higher floors. Steve wishes to go up 9 floors. There are K additional riders in the elevator, each of whom has randomly chosen one of the 11 higher floors as destination. On average, how many times will the elevator stop until Steve reaches his floor? Estimated number of stops = 1 Theoretical number is 1 steve(): Steve gets on an elevator going up. There are 11 higher floors. Steve wishes to go up 9 floors. There are K additional riders in the elevator, each of whom has randomly chosen one of the 11 higher floors as destination. On average, how many times will the elevator stop until Steve reaches his floor? Estimated number of stops = 1.72675 Theoretical number is 1.72727 steve(): Steve gets on an elevator going up. There are 11 higher floors. Steve wishes to go up 9 floors. There are K additional riders in the elevator, each of whom has randomly chosen one of the 11 higher floors as destination. On average, how many times will the elevator stop until Steve reaches his floor? Estimated number of stops = 2.38875 Theoretical number is 2.38843 steve(): Steve gets on an elevator going up. There are 11 higher floors. Steve wishes to go up 9 floors. There are K additional riders in the elevator, each of whom has randomly chosen one of the 11 higher floors as destination. On average, how many times will the elevator stop until Steve reaches his floor? Estimated number of stops = 2.9886 Theoretical number is 2.98948 steve(): Steve gets on an elevator going up. There are 11 higher floors. Steve wishes to go up 9 floors. There are K additional riders in the elevator, each of whom has randomly chosen one of the 11 higher floors as destination. On average, how many times will the elevator stop until Steve reaches his floor? Estimated number of stops = 5.60598 Theoretical number is 5.60722 stopping(): From a population of 5 indexed values, the highest is sought. Values are to be discovered in order of index. When value I is discovered: * it may be rejected, and the next value discovered, or * it may be accepted, and the process is terminated. A strategy is to view S items in a row, and then accept the very next item that is larger than max(S). Given N, what is S, and what are the chances that this process will produce the maximum? Population size N = 5 Optimal sample size S = 2 Ratio N / S = 2.5 Probability of success = 0.433333 stopping(): From a population of 10 indexed values, the highest is sought. Values are to be discovered in order of index. When value I is discovered: * it may be rejected, and the next value discovered, or * it may be accepted, and the process is terminated. A strategy is to view S items in a row, and then accept the very next item that is larger than max(S). Given N, what is S, and what are the chances that this process will produce the maximum? Population size N = 10 Optimal sample size S = 3 Ratio N / S = 3.33333 Probability of success = 0.39869 stopping(): From a population of 20 indexed values, the highest is sought. Values are to be discovered in order of index. When value I is discovered: * it may be rejected, and the next value discovered, or * it may be accepted, and the process is terminated. A strategy is to view S items in a row, and then accept the very next item that is larger than max(S). Given N, what is S, and what are the chances that this process will produce the maximum? Population size N = 20 Optimal sample size S = 7 Ratio N / S = 2.85714 Probability of success = 0.384209 stopping(): From a population of 50 indexed values, the highest is sought. Values are to be discovered in order of index. When value I is discovered: * it may be rejected, and the next value discovered, or * it may be accepted, and the process is terminated. A strategy is to view S items in a row, and then accept the very next item that is larger than max(S). Given N, what is S, and what are the chances that this process will produce the maximum? Population size N = 50 Optimal sample size S = 18 Ratio N / S = 2.77778 Probability of success = 0.374275 stopping(): From a population of 100 indexed values, the highest is sought. Values are to be discovered in order of index. When value I is discovered: * it may be rejected, and the next value discovered, or * it may be accepted, and the process is terminated. A strategy is to view S items in a row, and then accept the very next item that is larger than max(S). Given N, what is S, and what are the chances that this process will produce the maximum? Population size N = 100 Optimal sample size S = 37 Ratio N / S = 2.7027 Probability of success = 0.371043 sylvester_quadrilateral(): Estimate the probability that four points, chosen uniformly at random in the unit circle, form a concave (=nonconvex) quadrilateral. Estimated concave probability = 0.295555 Expected value is 0.29552. umbrella(): A person has XI umbrellas at home, and YI at the office. With probability P, it will be raining at any given time. If it is raining, the person takes an umbrella from one place to the other. How many walks will the person take before running out of umbrellas? Use graphics to display results. Graphics saved as "umbrella.png" umbrella(): A person has XI umbrellas at home, and YI at the office. With probability P, it will be raining at any given time. If it is raining, the person takes an umbrella from one place to the other. How many walks will the person take before running out of umbrellas? Use graphics to display results. Graphics saved as "umbrella.png" walk(): A pedestrian begins M blocks east and M blocks north of a destination. At each intersection, there is a stop light which is set randomly, and switches after 1 minute. Until reaching avenue 1 or street 1, the pedestrian always crosses the intersection in accordance with the stop light. Thereafter, the pedestrian must wait at each stop light encountered. What is the average wait for stop lights? Estimated waiting time = 0.75411 walk(): A pedestrian begins M blocks east and M blocks north of a destination. At each intersection, there is a stop light which is set randomly, and switches after 1 minute. Until reaching avenue 1 or street 1, the pedestrian always crosses the intersection in accordance with the stop light. Thereafter, the pedestrian must wait at each stop light encountered. What is the average wait for stop lights? Estimated waiting time = 1.22616 walk(): A pedestrian begins M blocks east and M blocks north of a destination. At each intersection, there is a stop light which is set randomly, and switches after 1 minute. Until reaching avenue 1 or street 1, the pedestrian always crosses the intersection in accordance with the stop light. Thereafter, the pedestrian must wait at each stop light encountered. What is the average wait for stop lights? Estimated waiting time = 1.76292 walk(): A pedestrian begins M blocks east and M blocks north of a destination. At each intersection, there is a stop light which is set randomly, and switches after 1 minute. Until reaching avenue 1 or street 1, the pedestrian always crosses the intersection in accordance with the stop light. Thereafter, the pedestrian must wait at each stop light encountered. What is the average wait for stop lights? Estimated waiting time = 2.50072 walk(): A pedestrian begins M blocks east and M blocks north of a destination. At each intersection, there is a stop light which is set randomly, and switches after 1 minute. Until reaching avenue 1 or street 1, the pedestrian always crosses the intersection in accordance with the stop light. Thereafter, the pedestrian must wait at each stop light encountered. What is the average wait for stop lights? Estimated waiting time = 3.95794 walk(): A pedestrian begins M blocks east and M blocks north of a destination. At each intersection, there is a stop light which is set randomly, and switches after 1 minute. Until reaching avenue 1 or street 1, the pedestrian always crosses the intersection in accordance with the stop light. Thereafter, the pedestrian must wait at each stop light encountered. What is the average wait for stop lights? Estimated waiting time = 5.63146 digital_dice_test(): Normal end of execution. 05-Jan-2023 17:02:00