The Buffon Needle Experiment. The following experiment was devised by Comte Georges-Louis Leclerc de Buffon (1707–1788), a French naturalist. A needle of length 1 inch is dropped onto paper that is ruled with lines 2 inches apart. If the needle drops onto a line, we count it as a hit. (See Figure 9.) Buffon discovered that the quotient tries/hits approximates π.
For the Buffon needle experiment, you must generate two random numbers: one to describe the starting position and one to describe the angle of the needle with the x-axis. Then you need to test whether the needle touches a grid line.
Generate the lower point of the needle. Its x-coordinate is irrelevant, and you may assume its y-coordinate ylow to be any random number between 0 and 2. The angle π between the needle and the x-axis can be any value between 0 degrees and 180 degrees (π radians). The upper end of the needle has y-coordinate
The needle is a hit if yhigh is at least 2 as shown in Figure 10. Stop after 10,000 tries and print the quotient tries/hits. (This
Figure 9
The Buffon Needle Experiment
Figure 10
A Hit in the Buffon Needle Experiment
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Big Java Late Objects
Additional Engineering Textbook Solutions
C How to Program (8th Edition)
Programming in C
Concepts Of Programming Languages
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Objects (6th Edition)
- JAVA Coding Problem Holi is celebrated in India as a festival of colours and your friend Khan from India has gifted you X packets of colours. Now you are planning to make a beautiful rangoli, to make it you need to map all colours pairwise distinct, so that they look attractive. To do so, you can mix the colours zero or more times: Pick any two random colours. Let's denote their weight by t and u. Mix the colour with second colour. After the process, the value of the first colour remains t, but the weight of the second colour changes to t+ u. Now you have to develop the code to find the minimum number of mixing operations you needs to perform to make a beautiful Rangoli. Sample Test Case Scenario: 1 3 321 Output:arrow_forwardComputer Science There is an n × n grid of squares. Each square is either special, or has a positive integer costassigned to it. No square on the border of the grid is special.A set of squares S is said to be good if it does not contain any special squares and, starting fromany special square, you cannot reach a square on the border of the grid by performing up, down,left and right moves without entering a cell belonging to S. 5 3 4 9 4 X 3 6 1 9 X 4 1 2 3 5 - Design an algorithm which receives an arbitrary n × n grid, runs in time poly-nomial in n and determines a good set of squares with minimum total cost.arrow_forwardLittle Frank loves mathematics. Every day, he solves some mathematical problems to improve his skill. A few days ago, he found a popular problem about turtles. The problem is as follows. Little Frank is given R rectangles, numbered 1 through R. The width and height of the i-th rectangle are Ni and M¡ unit respectively. There is a turtle located on the top-left corner of each rectangle. For each rectangle, count the number of ways the turtle can reach the bottom-right corner, if each turtle can only move right or down 1 unit at any time. The turtle is not allowed to move outside the rectangle, but, of course, the turtle can move on the boundary of the rectangle. In less than one second, this problem was solved for all rectangles. He felt that the problem was too easy. This morning, Little Frank wanted more challenges. Thus, for each rectangle į, he cut and removed a rectangle of A¡ x Bị unit from the top-right corner. See the following figure for detail. Bị Mi He could not solve this…arrow_forward
- In a Chess match "a + b", each player has a clock which shows a minutes at the start and whenever a player makes a move, b seconds are added to this player's clock. Time on a player's clock decreases during that player's turns and remains unchanged during the other player's turns. If the time on some player's clock hits zero (but not only in this case), this player loses the game. N+1 There's a 3 + 2 blitz chess match. After N turns (i.e. moves made by 2 N white and moves made by black), the game ends and the clocks of the two 2 players stop; they show that the players (white and black) have A and B seconds left respectively. Note that after the N-th turn, b = 2 seconds are still added to the clock of the player that made the last move and then the game ends. Find the total duration of the game, i.e. the number of seconds that have elapsed from the start of the game until the end.arrow_forwardA robot is initially located at position (0, 0) in a grid [−5, 5] × [−5, 5]. The robot can move randomly in any of the directions: up, down, left, right. The robot can only move one step at a time. For each move, print the direction of the move and the current position of the robot. If the robot makes a circle, which means it moves back to the original place, print “Back to the origin!” to the console and stop the program. If it reaches the boundary of the grid, print “Hit the boundary!” to the console and stop the program. A successful run of your code may look like: Down (0,-1) Down (0,-2) Up (0,-1) Left (-1,-1) Left (-2,-1) Up (-2,0) Left (-3,0) Left (-4,0) Left (-5,0) Hit the boundary! or Left (-1,0) Down (-1,-1) Right (0,-1) Up (0,0) Back to the origin! Instructions: This program is to give you practice using the control flow, the random number generator, and output formatting. You may not use stdafx.h. Include header comments. Include <iomanip> to format your output. Name…arrow_forwardA popular word game involves finding words from a grid of randomly generatedletters. Words must be at least three letters long and formed from adjoining letters.Letters may not be reused and it is valid to move across diagonals. As an example,consider the following 4 * 4 grid of letters: A B C DE F G HI J K LM N O P The word “FAB” is valid (letters in the upper left corner) and the word “KNIFE”is valid. The word “BABE” is not valid because the “B” may not be reused. Theword “MINE” is not valid because the “E” is not adjacent to the “N”. Write a program that uses a 4 * 4 two-dimensional array to represent the gameboard. The program should randomly select letters for the board. You may wishto select vowels with a higher probability than consonants. You may also wish toalways place a “U” next to a “Q” or to treat “QU” as a single letter. The programshould read the words from the text file words.txt (included on the website withthis book) and then use a recursive algorithm to…arrow_forward
- Write a program that prints an mxn matrix whose dimensions are specified by the user. Let the matrix values be random variables. You must use it within the repetition cycle. Example format: Enter dimension of matrix mxn: 2 4 The 2x4 matrix is : 1 2 3 4 5 6 7 8arrow_forwardPython Programming Lab Dr.D has invented yet another invention: the hateinator. He wants to test it on a group of N people (numbered 1 through N). The hateinator may be used any number of times; to use it once, Dr.D should divide these N people into two groups and press the fire button on the hateinator. We call each such grouping a Doofish set. Afterwards, there will be hatred between each two people who were in different groups. The hatred does not disappear ― any two people that hate each other before the hateinator is used still hate each other afterwards. The hateinator uses a lot of power. Let's denote the number of times it is used by K. Then, it consumes K⋅N units of power. Dr.D cannot afford to use the hateinator if this number exceeds 106. Dr.D has done the math and computed the most evil hatred system: a situation with some M pairs of people who hate each other. You are given these pairs. There must not be any other pair of people who hate each other. Initially, there is no…arrow_forwardWelcome to the era of Aladdin and the great magic lamp. This is 1st of January and Aladdin will be in jail for one year. He was recently caught for helping forty thieves. Now he has nothing to do. But he knows that Jasmine is waiting for him. At some point he got an idea to give Jasmine a magical program that can find intervals of months from a year. This allows her to easily determine how long it will take for Aladdin to get out. Then Aladdin rubs the magic lamp and The Genie appears. Then he asked The Genie to make such a magical program. Unfortunately the Genie doesn't know programming and he wants your help to create that magical program. Genie will give you N as the day of the year and you have to print in which month that day is. Input Format Input will contain one line with a single integer N, day of the year. Constraints 1 <= N <= 365 Output Format Print a single line containing the name of month. Be careful about the newline ('\n') at the end. Sample Input 0 1 Sample…arrow_forward
- Professor X wants his students to help each other in the chemistry lab. He suggests that every student should help out a classmate who scored less marks than him in chemistry and whose roll number appears after him. But the students are lazy and they don't want to search too far. They each pick the first roll number after them that fits the criteria. Find the marks of the classmate that each student picks. If a student is unable to find anyone print -1.Note: one student may be selected by multiple classmates. Input:First line of input contains number of testcases T. For each testcase, there will be two lines, first of which contains N denoting the number of students in the class. Second line contains N space separated integers denoting the marks of each student roll number wise. Output:For each roll number, print the marks of the student he choses to help. Your Task:Complete the function help_classmate() that takes array containing marks and integer N as input parameters and returns a…arrow_forwardhi! i am a newbie in python. please help me on this problem. also, please send a screenshot for a proof that the codes works. thanks~arrow_forwardThis does not appear to be the answer to this question; Cheese's position is randomly generated in a 5x5 grid. The initial positions are x,y. The position of Cheese is not specified as (3, 4)arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr