Year 8 Mathematics Investigation - The Cartesian Plane and Pythagorean Triples
Year 8 Mathematics Investigation - The Cartesian Plane and Pythagorean Triples
Year 8 Mathematics Investigation - The Cartesian Plane and Pythagorean Triples
Pythagorean Triples
May 5, 2023
1 INTRODUCTION
This investigation has three parts which require you to think carefully and design a set of computa-
tional algorithms (which altogether make a program). You are to then implement your algorithms
in code using the Python programming language. You can use Grok Academy’s Python Playground
to write your code (keep in mind that Python Playground 13 will be reserved for submission). It is,
however, strongly recommended that you use VS Code or PyCharm to develop your program.
If you need help setting these up, email [email protected] or come to the Maths
office. If you have requested a mentor, you can contact them for help.
Be aware that most of the marks for this investigation will be allocated to the design work and
explanation of your algorithms. It is therefore wise to create a slide presentation onto which you
can start adding your designs. This investigation will frequently refer to the slides that you will be
adding to as you go.
You must carefully document the process that you go through and include your designs and decisions
so that you can present them to a small group of randomly-selected classmates. To help you with
this, make sure to follow the process outlined below;
1. Read through each part of this document right away and take notes. Make sure to record
and justify any assumptions you make.
2. Re-read each of the three parts and design your algorithms in English using brief
dot-points (with indentation to indicate blocks of instructions) or you can use dia-
grams/pseudocode/flowcharts if you prefer. Add these to your presentation slides.
3. Make sure your overall design has separate parts that can be shared or reused and thus
implementable in Python using functions. Refer to the Python Functions Tutorial posted in
Connect earlier this year.
4. Once you have finished the first draft of your design, review it and make modifications as
needed. Document any changes you make and be sure to add them to your slides.
5. Code and test each part. If you find that your code starts to deviate from your design, just
document the changes you make and provide reasons. You can make annotations to your
original design.
The details of what your program needs to do for each section will be given below, together with
the number of marks allocated out of 100. Additional informal guidelines can be found by typing
(then running) import this into Grok Academy or VS Code/PyCharm.
Make sure you document your code using # comments. Code comments are like sunscreen – if in
doubt use lots and lots.
1
1.1 Create and explain a reusable means of achieving translations (15 Marks)
This investigation takes place on a Cartesian plane of a specified size. There will initially be three
entities on it; player one, player two and destination. When your program first runs, the three
entities will be placed randomly on the Cartesian plane. The two players will take turns moving a
short distance towards the destination. The destination will stay put.
The main restriction is that the players can only move along the hypotenuse of a right-angled
triangle, and the lengths of the sides of the triangle must form a primitive Pythagorean triple. The
non-hypotenuse sides (called a and b) must be parallel to the x and y axes of the Cartesian plane.
The triangle can be oriented such that the players can move roughly towards the top right, top
left, bottom left and bottom right of the Cartesian plane.
For example, let us say player one wants to move 5 units roughly towards the top left corner of
the plane. Using the Pythagorean triple (3, 4, 5), they can move 3 units left and 4 units up (a
translation of [-3,4]) or they can move 4 units left and 3 units up (a translation of [-4,3]).
Notice the subtle change in direction. If player two wants to move 13 units roughly towards the
bottom left corner of the plane, they can apply a translation of [-5,-12] or [-12,-5] using the
Pythagorean triple (5, 12, 13). Notice the much more pronounced change in direction between the
two translations.
You need to find a way to translate a player a specified distance in a particular direction. Since
trigonometry is outside the scope of this investigation (do NOT use trigonometry), we are going to
specify eight approximate directions numbered 1 to 8. The eight directions are obtained by dividing
each quadrant of the cartesian plane diagonally in two. Thus direction number 1 will be from 0 to
45 degrees (0 degrees is in the positive direction of the x-axis and angles increase anticlockwise).
Direction 2 is from 45 to 90 degrees, direction 3 from 90 to 135 degrees and so on, all the way to
direction 8 from 315 to 360 degrees.
Thus player one can request to move 5 units in direction 3 which can be achieved by translating
[-3,4] but moving 5 units in direction 4 requires [-4,3]. Player two moving 13 units in direction
5 needs a translation of [-12,-5] while moving 13 units in direction 6 needs [-5,-12]. Note that
when your program runs, you will simply enter 13 <space> 5 or 13 <space> 6 to specify distance
and direction. Make sure you fully understand how all of this works - discuss it with classmates
before you start your design work.
By the way, these translations will be in our imaginations at first. Your algorithms will simply be
manipulating coordinates and printing out the locations of the players and the destination. You
are not required to visually display the plane and players as they move around (this will be an
optional extra at the end).
To simplify your task, you will be provided a list with the first 127 primitive Pythagorean triples
sorted by the hypotenuse (see section 3.2 on page 6 for more information). Do not add to this
list. To earn full marks in this section, you need to think carefully about how to move a distance
of c units in direction n using a pythagorean triple (a, b, c) from the list. Using look-up tables
can help, where you can somehow link directions to translations. Your design will eventually be
packaged into a reusable Python function that can be called to execute a required translation. Your
design work here is central to the entire investigation - make sure to document what you decide
to do (and exactly how it works) in your presentation slides. If you choose to implement these
conversions another way other than using the look-up tables, describe in your presentation what
you did and how it works.
2
1.2 Use functions, validate input and document imports (15 Marks)
As you work on this investigation, make sure you do not simply import a library (either built-in,
or from the internet) and use it to do all of the work for you. For instance, doing the following to
calculate distance will not earn any marks:
import math
print(math.dist([2,-4],[-5,3])
The intent is for you to write your own versions of the functions (in this case, dist()) that perform
the required operations so that you gain a deep understanding of how to think about, and design
computational algorithms. This knowledge will also allow you to be able to understand and explain
code that you obtain from sources on the internet as you work on this task.
If you do import some libraries (such as numpy or scipy or pandas), make sure to explain in your
slides exactly how you are using them, making it clear that they only play a supporting role and
that they do not implement entire parts of your investigation.
It is essential that you use functions throughout (worth 10 marks) and you must demostrate this
during your presentation. You should also validate all input data such as rejecting negative lengths
and directions beyond 1 and 8. Document all the kinds of validation that you do (worth 5 marks).
person_one = {
'name': 'Rene Descartes',
'birthplace': [47.3, 0.67], # Approx Long and Lat
'trips_around_the_sun': 53,
}
If you need more practice with dictionaries, consult Grok Academy’s Introduction to Programming
2 (Python) Course, module 2. Document how you designed your three dictionaries in your slides.
3
2.2 Randomly place the players and the destination (5 Marks)
The size of the cartesian plane on which the program events unfold will be from -800 to +800 in
both the x and y directions. When your program runs, it should generate three sets of random
integer coordinates and assign them to player one, player two and the destination by storing
them in the relevant dictionaries. You should import and use the Python random module to achieve
this and document your work for this section in your presentation slides.
4
3 PART II: TAKE TURNS MOVING PLAYERS
3.1 Use the personal space buffer to identify a winner (15 Marks)
As you’ve already worked out, the aim of the program is for the two players to take turns and
compete to see who can reach the destination first. A player is deemed to have reached the
destination if their coordinates are within the personal space buffer of the destination. You should
have a function that can be called to check for this and indicate that the player has won. You will
need to think about how you can ascertain when a player has reached the destination’s personal
space and document your thoughts and designs/algorithm in your slides.
Since each human player can see information about the other player’s location and the midpoint
coordinates between them, a player can move towards another. If a player reaches another player’s
personal space buffer, the player who made the move wins. It is therefore important for players to
avoid each other as they advance towards the destination. Once again, document your design work
for this in your slides and make note of any ways that you have reused your previous computational
algorithms.
3.2 Move players along the hypotenuse of a right-angled triangle (15 Marks)
Attached to this investigation is a file containing a list of 127 primitive Pythagorean triples. Do
not add to this list. The list (of lists) looks like this:
triples = [ [3, 4, 5], [5, 12, 13], [8, 15, 17] ... [555, 572, 797] ]
The list has been doubly sorted for you, in ascending order by the length of the hypotenuse, and
within each triple, the lengths are also in ascending order so that the last number is always the
hypotenuse. Keep this in mind as you design your algorithms. Below are some examples of how
you can query the list:
Remember that a player can effectively move along the hypotenuse c by using a translation involving
a and b. It is therefore unlikely for a player to take a straightforward path to the destination - it
will have to be a zig-zag path that sometimes doubles back. Clearly, not every integer length from
1 to 800 is available. Thus if a player requests to move distance 15 in direction 2, the requested
distance should be interpreted as ‘at most 15 units’ meaning you should pick the closest hypotenuse
that is at most 15. In this case, allow them to only move 13 units in direction 2.
5
You should therefore write a function that accepts the requested distance and direction, and only
move the player the allowed distance in the requested direction. Remember, the actual translation
that achieves this goal is [5,12]. Detail your thoughts and design work in your slides and make
sure you can explain your algorithm.
After a player moves, your program should call the relevant function and display their updated
information, as well as the destination’s information (hopefully in different colours). The second
human player can make use of this knowledge during their turn.