Question

(1)Make a simulation program of the Galton board. Keep in mind that your program must be...

(1)Make a simulation program of the Galton board. Keep in mind that your program must be simulation-based. The positions of the ball will be determined by the random functions.

(i) Assume that this Galton board is an unbiased board. In other words, the ball will have equal probability of moving to the left or to the right (50% vs. 50%). This Galton board has 10 levels. There are 10000 balls to drop from the center of the top level. The program will finally output the simulated result: the distribution of the numbers of balls in each position at the bottom level.

(ii) Assume that this Galton board is slightly biased (or tilted). The ball will have 47% of chance of moving to the left when it hits any peg, and 53% to the right. This Galton board has 10 levels and you run the simulation for 10000 balls. The program should finally output the result of distributions at the bottom level.

need code in python with comments

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Summary :

python code is pasted below which has comments inline and all the parameters can be changed at the begining of main program which go as input to the game .

Output for both 50,50 and 47,50 are shown as part of output .

Note : Input for bias require to be in decimals for eg [0.47, 0.50] for second case .

######################### Python Code ###########################

from random import choices

def get_next_position( current_level , current_position , probability) :
    # Define possible outcomes and respective probabilities
    outcomes = [0,1]
  
    # get randomly the output
    output = choices(outcomes , probability)
  
    next_position = current_level + current_position + output[0]

    return next_position
  

def cur_start( level ) :

    if level > 1 :
        return ( ( level - 1) + cur_start( level -1 ) )
    else :
        return 1 ;
      
  

if __name__ == '__main__':
    # Define Number of balls and levels
    num_balls = 10000
    num_levels = 10
    outcome_probability = [0.50 , 0.50]
  
    num_slots_bottom = num_levels + 1
  
    bottom_level = []
    for i in range(num_slots_bottom) :
        bottom_level.append(0)
      
    bottom_level_offset = int(1+ num_levels * (num_levels + 1 ) / 2)
    #print(" BottomLevel Offset " , bottom_level_offset)
  
    ## cur_pos - start with current position as level & cur_pos as 1 and start calculating level 2 position
    ##
    ##
    ##
    for cur_ball_num in range( num_balls ) :
        cur_pos = 1
      
        for level in range( 1 , 11 ):
            next_pos = get_next_position(level,cur_pos,outcome_probability)
            #print("Cur Pos : -> ", cur_pos , " Next Pos -> " , next_pos )
            cur_pos = next_pos
          
        # Increment ball count on the bottom level .
        #print(" Bottom level -> " , cur_pos , " Buttom count -> " , bottom_level[cur_pos - 56])
        bottom_level[cur_pos - bottom_level_offset] = bottom_level[cur_pos - bottom_level_offset] + 1
      
    print("( " + str(outcome_probability[0]*100) + "% , " + str( outcome_probability[1]*100) + "% )" )
    print(" Ball Count at Bottom Level : ")
    total_ball_count = 0
    for i in range(num_levels + 1):
        total_ball_count = total_ball_count + bottom_level[i]
        print(" slot : " , i , " --> ", bottom_level[i])
  
  
    print(" Total Ball Count : " , total_ball_count )

####################### End of Python Code #######################

#################### Output #####################################

usr@DESKTOP-VUMS 26N:/mnt/i/PRJ/Code/pyth$ python3 galton_board.py ( 47.0%, 53.0%) Ball Count at Bottom Level : slot: 0 --> 3

#################### End Output #####################################

Add a comment
Know the answer?
Add Answer to:
(1)Make a simulation program of the Galton board. Keep in mind that your program must be...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end, show the exact Output that's shown in Problem 2. CODE PROVIDED FOR PROBLEM 1: import java.util.Scanner; public class Problem1 {    public static void main( String [] args )    {        //N denoting the size of the board        int n;       ...

  • Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end show the exact Output that's shown in the Problem 2. CODE PROVIDED FOR PROBLEM 1: import java.util.Scanner; public class Problem1 {    public static void main( String [] args )    {        //N denoting the size of the board        int...

  • Must be done in Java. PROBLEM 2 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 2 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. PROBLEM 1 INFORMATION IF YOU NEED IT AS WELL: Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end, show the exact Output that's shown in Problem3. CODE PROVIDED FOR PROBLEM 2: import java.util.Scanner; public class Problem2 { public static void main( String [] args ) { //N...

  • The following guidelines outline the basic template for a robot vacuum cleaner game. The game must be implemented in c programming language. It mimics a robotic vacuum cleaner. The code must only use...

    The following guidelines outline the basic template for a robot vacuum cleaner game. The game must be implemented in c programming language. It mimics a robotic vacuum cleaner. The code must only use the following libraries: #include <math.h> #include <stdlib.h> #include <string.h> #include <limits.h> and any .graphics and .timers libraries. The guidelines are outlined as follows: Terminal Set-up: you may assume that the terminal will be quite large, for example, on the order of 150×50, or more. Status Display: The...

  • The following guidelines outline the basic template for a robot vacuum cleaner game. The game must...

    The following guidelines outline the basic template for a robot vacuum cleaner game. The game must be implemented in c programming language. It mimics a robotic vacuum cleaner. The code must only use the following libraries: #include <math.h> #include <stdlib.h> #include <string.h> #include <limits.h> and any .graphics and .timers libraries. The guidelines are outlined as follows: Terminal Set-up: you may assume that the terminal will be quite large, for example, on the order of 150×50, or more. Status Display: The...

  • please use python and provide run result, thank you! click on pic to make it bigger...

    please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...

  • Can you please provide the formula for the worksheet also. CASE PROBLEMS Level 1- Analyzing Sales...

    Can you please provide the formula for the worksheet also. CASE PROBLEMS Level 1- Analyzing Sales for Crèmes Ice Cream Judd Hemming is the eastern regional marketing manager for Crèmes Ice Cream. Eac quarter, he completes two separate analyses: an analysis comparing ice cream flavor sale volumes from all regional locations with the same quarter sales volumes from the previou year and an analysis comparing total sales in dollars, including mean, median, mode, and standard deviation, of sales by store....

  • In your judgement, and given only the facts described in this case, should the management of...

    In your judgement, and given only the facts described in this case, should the management of Massey energy Company be held morally responsible for the deaths of the 29 miners? Explain in detail. Suppose that nothing more is learned about the explosion other than what is described in this case. Do you think Don Blankership should be held morally responsible for the deaths of the 29 miners? Explain in detail. Given only the facts described in this case, should the...

  • Summary should briefly analyze the central problems and issues of the case and provide some analysis...

    Summary should briefly analyze the central problems and issues of the case and provide some analysis and suggestions. Thank you. Lean Initiatives and Growth at Orlando Metering Company It was late August 2002 and Ed Cucinelli, vice president of Orlando Metering Company (OMC), sat in his office on a late Saturday morning. He had come in to prepare for some strategic planning meetings that were scheduled for the upcoming week. As he noticed the uncommon silence in the building, Ed...

  • Case: Enron: Questionable Accounting Leads to CollapseIntroductionOnce upon a time, there was a gleaming...

    Case: Enron: Questionable Accounting Leads to CollapseIntroductionOnce upon a time, there was a gleaming office tower in Houston, Texas. In front of that gleaming tower was a giant “E,” slowly revolving, flashing in the hot Texas sun. But in 2001, the Enron Corporation, which once ranked among the top Fortune 500 companies, would collapse under a mountain of debt that had been concealed through a complex scheme of off-balance-sheet partnerships. Forced to declare bankruptcy, the energy firm laid off 4,000...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT