Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

As kids we visited our grandparents in Minnesota and our greatest joy was catchi

ID: 3825318 • Letter: A

Question

As kids we visited our grandparents in Minnesota and our greatest joy was catching frogs out by the lake.  (Links to an external sout by the lake. This one looks a lot like the one I called Peter (named after my cousin).

Unfortunately, being kids, we were not super kind to the animals (though our attention was a bit less invasive than that of the neuroscientists who have studied this species a lot!). One thing we did was to have frog races. Each kid would take their most athletic looking frog and place them on a line we drew in the dirt. The first frog to reach the finish line that we drew a few feet away was the winner! Of course, we would start the frogs in the right general direction and we were allowed to pick up any frogs that strayed off the course and put them back on, facing in the direction of the finish line. These frogs sometimes jumped a little, sometimes did great leaps, sometimes turned sideways or all the way around, and more often than not, did absolutely nothing. This is an example of Brownian motion (Links to an external site.). Eventually a frog would actually cross the finish line!

This project is to do a simulation of those childhood frog races. You will have a class for the race course and a class for frogs and an driver function for the whole race. Each frog will be registered in the race, get his unique bib number, and be set on the starting line with the heading toward the finish line. The frogs will have a method, doSomething, that when invoked will randomly, change heading, jump forward a random amount, or do nothing at all. The race course will host all the frogs and will invoke the doSomething method to move them along the course. If any of the frogs strays from the course, they will be (gently) re-placed on the boundary with a heading toward the finish line. When a frog crosses the finish line, a winner will be declared and the race will be over.

You will also, of course, provide an animation using turtle (apropos, yes?) of the race. We'll also collect some data on the frogs' paths in anticipation of making graphs and charts to help us analyze their motion.

I'll give you the race function, here:

Your assignment is to write the Frog class and the RaceCourse class such that they can be invoked by the race function as written above and behave as demonstrated in the video.

Write the Frog class first and play with it so you can see it working, then write the RaceCourse class but just do the simulation. Then, finally, add in collection of the path data for each frog in RaceCourse in instance variable, paths.

A Frog object keeps track of one of the frogs and stores its owner's name and its color along with an assigned bib number (the first frog gets 1, the next 2, etc.). Internally, the frog object also has it's own turtle object. This is created like this (you'll recognize this as an object instantiation from the class Turtle):

From then on you give commands to that object in order to manipulate that particular turtle. You'll want to set the turtle's color to be the same as the frog, e.g.,

The Frog class should have the following methods: __init__ to initialize the frog (takes a name and a color); __str__ so we can print out a frog with print(frog) which produces, for example "#1, Amy's green frog"; position, which just moves the frog's turtle to the given position; place, which takes an x and y coordinate and a heading and moves the frog to that location and heading; and doSomething, which randomly jumps the frog or spins the frog or does nothing. The amount of motion for a jump is done randomly a distance of one of 2, 5, 10, 12, 15, 20 or 30 units. Similarly, the amount of spin is done randomly 5, 7, 10, 15, 25, 45, 75 or 90 degrees randomly right or left.

I'll help you with the math required to figure out the change in x and y coordinates to go a given distance along the current heading:

The RaceCourse class sets up the race course and allows addition of frogs into the race. Upon starting the race, the course moves the frogs to their beginning position heading toward the finish line. The course then repeatedly invokes the doSomething method for each frog until there is a winner. Along the way, it corrects any frog that has gone off-course by moving it to the boundary and heading it toward the finish (i.e., straight right).

The RaceCourse should have, at minimum, the following methods: __init__; addFrog; go; and winner, which returns the frog object that won the race. In the final version that you hand in, it must also have an instance variable, paths, which is a dictionary keyed by the frogs' bib numbers with values that are lists of each of that frog's positions during the race.

I also suggest you break down the tasks of the required methods by adding some more methods to do various pieces of what go has to accomplish: placeFrogs, which gets the frogs into their correct starting position and also draws the boundaries and prints the titles; moveFrogs, which calls doSomething once for each frog and then does the course correction, if necessary; offCourse, takes a frog and returns True if that frog is off the course; correct, which takes a frog that is off course and moves it to the closest boundary and sets its heading to 0 (toward the finish line); and announceWinner that displays the message in the middle of the screen at the end.

Once you have these in place, then the go method is simply:

What it should do : https://www.screencast.com/t/ny3YUEwlr

Explanation / Answer

odular multiplication, want conversions from RNS to binary or RNS to AN alternative RNS. This transformation is
not trivial, and most of the algorithms rely of it. it's the rationale why we have a tendency to target this operation, specially
from RNS to RNS that is employed in cryptography,11 analyzing the influence of the selection of the coprime n-uple
defining the RNS basis.
We initial gift the classical conversion algorithms from RNS to RNS or alternative representations. Then, we
analyze these ways through the purpose of read of the RNS bases. we have a tendency to propose some criteria of bases choice
to obtain economical conversions. And we end, within the conclusion, with a discussion around RNS.
2. SOME GENERALITIES ON THE CONVERSION
When we propose to use RNS to represent numbers, the primary question is: what's the price of the conversion to
and from these systems? it's clear that the interpretation from a classical illustration to RNS is just like a
modular reduction. one amongst the foremost trivial means is to store all the powers of the number modulo every part of
the RNS basis.12–14 Thus, if we have a tendency to think about the RNS basis (m1, m2, . . . , mn) with M =
Qn
i=1 mi < T wherever is
the number of the classical illustration, then we've got to store T n values of size T /n digits, in alternative words T
2
digits, for exploitation the subsequent formula:
xi = |X|mi
=


X
T
j=1
j ×
j


mi
=


X
T
j=1
j ×


j


mi


mi
(1)
We assume that the standard multiplier-adder is that the basic operator of RNS computing. Hence, the conversion
from illustration to RNS are often worn out T iterations. currently if we have a tendency to think about a full parallelization, with n
modular multiplier-adders, this conversion are often index (ie O(log(T))). however during this paper we have a tendency to focus our
attention to the conversion from RNS to RNS or to illustration.
To modify our future discussions, we have a tendency to think about that = two, that each one the mi have constant variety t of bits,
and for the RNS to RNS conversion the 2 bases have constant variety of moduli.
We note B = (m1, m2, . . . , mn) and Be = (mf1, mf2, . . . , mfn) the 2 RNS bases that we are going to use.
2.1. From the Chinese Remainder Theorem
In the proof of the Chinese Remainder Theorem we will show, that an answer of the subsequent system:



X x1 (mod m1)
... ... ...
X xn (mod mn)
(2)
can be created from the formula:
X =

x1 |M1|
1
m1 M1 + x2 |M2|
1
m2 M2 + . . . + xn |Mn|
1
mn Mn

M
(3)
Where, Mi =
M
mi
for one i n and |Mi
|
1
mi
represents the inverse of Mi modulo mi
.
It is obvious that the analysis of a such expression is serious. To modify a bit bit the equation (3) we have a tendency to
consider i = xi
|Mi
|
1
mi mod mi
, thus we have a tendency to get a replacement expression for X:
X =
Xn
i=1
iMi
!
mod M (4)
Despite this transformation, every term stays an excellent price of constant vary than M. thus we have a tendency to deduce that the
cost of the conversion from RNS to binary illustration is akin to n standard product modulo AN mi
, n
products of an outsized variety by alittle one, and n one additions of enormous numbers and a discount modulo M.
Here again, we will put to get a index time quality, however the operators are going to be Brobdingnagian and
not realistic. Now, if the amount n of moduli is little, like for a few DSP, the equation (4) offers a decent
solution.15, 16
The conversion RNS to RNS is analogous, we are going to build constant quite operations on every modulo of the new
basis Be, the equation (3) becomes for j :
X =

x1 |M1|
1
m1
|M1|mfj
+ x2 |M2|
1
m2
|M2|mfj
+ . . . + xn |Mn|
1
mn
|Mn|mfj

mfj
(5)
Thus, this analysis desires n standard product modulo AN mi
, and for every modulo of the new RNS basis
n standard product (of tiny numbers), and n one standard additions of residues and a discount modulo M.
So if we have a tendency to don't take under consideration the ultimate reduction, we want n(n + 1) standard product and n(n 1) standard
additions on residues. we've got to note that we will have an excellent degree of parallelization.
Now, the reduction modulo M is that the main downside of this approach. in reality most of the strategy projected
to find such that:
X + M =
Xn
i=1
iMi
!
(6)
Hence, once is decided, M are often subtracted from the second member of equation (6). This remark is
also obtainable for the RNS to RNS conversion.
A. P. Shenoy and R. Kumaresan have projected to use an additional modulo to seek out this issue.17 during this technique
all the computing is finished with integers. AN alternative purpose of read is to seek out AN approximation of with floating
point cell.9, 18, 19
2.1.1. Shenoy Kumaresan
This technique relies on the information of the residue modulo an additional co-prime American state. thus X is outline by its RNS
representation (x1, x2, . . . , xn), and that we apprehend Xe = X mod American state. Hence, from expression (6) we will deduce the
residue of X + M modulo me:
= (X + M) mod American state =

Xn
i=1
i
|Mi
|me

me
(7)
Thus, we have
= ( xe) × |M|
1
me mod American state (8)
This analysis desires n standard product and n1 standard additions on residues. Then the ultimate reduction
is done with a product by of M (|M|mfj
for RNS to RNS) and a subtraction.
But this condition on the additional modulo can't be continuously glad. it's not obvious of maintaining the
knowledge of the residue modulo American state throughout the various calculuses. So, we have a tendency to should think about AN approach obtainable
just with the RNS illustration