Java AP EXTRA: LOOP APPLICATION:
SIMULATION & MATH PROBLEMS AP LESSON NOTE SIMULATING
AN EVENT MANY TIMES Computing has brought us the ability
to simulate an event very very quickly and hence
very often. This can be done simply by
repeating a calculation many times in a loop.
CASE
SCENARIO – COIN FLIP Consider an event such as the flipping
of a coin. Let's assume that there is
a 50% chance of a result of HEADS and a 50% chance of a results of
TAILS. A computer can easily simulate
such an event by simply generating a random number. Because a computer can do this so quickly,
we can simulate this millions of times in less than a second. SOLVING
MATH PROBLEMS While some math problems require very
innovative thinking, there are some math problems that simply require us to
check a lot of possible values for something.
For example, proving that there is an
infinite number of prime numbers requires innovative thinking. However, checking if any single number is
a prime is a perfect problem for a computer as it simply has to check if the
number has any divisors and it does so by checking every value that is
smaller than that number. Math problems that ask for the odds
that something will happen can be solved by trying to do something over and
over and over again. For example, the
problem "How common are prime numbers between one million and two
million?" can be attacked by randomly generating a number in that range
and checking if it's a prime number or not.
Then, we repeat that many times (1000 or more probably) to see how
commonly we randomly chose a prime number.
|
|
|