In LEGO kits for building robots, there is generally a substantial supply of "beams" or "liftarms" in various lengths (e.g., see beam image) as well as pins (e.g. as shown in this image of pins from brickshop.co.uk) to hold them together.
While LEGO beams come in varying lengths, they all have holes spaced at a regular interval that we will refer to as one LEGO unit (about 8mm). In most LEGO constructions, beams are generally placed horizontally or vertically along an underlying virtual grid where the holes fall. But it may also be desirable to place beams along a diagonal as in this image of a triangular construction where most of the beams are horizontal and vertical but a set of gears is sandwiched between beams running diagonally. In this example, the beams essentially form a right triangle with sides of length 7, 11, and 13 in LEGO units, but these lengths do not exactly satisfy the Pythagorean Theorem.
Recall that the Pythagorean Theorem provides a relationship between the side lengths in a right triangle, a triangle that contains a right (90⚬) angle. It tells us that
a2 + b2 = c2where c is the length of the hypotenuse (the longest side, which is opposite the right angle) and a and b are the lengths of other sides (legs). (A nice site with graphical illustrations is https://www.mathsisfun.com/pythagoras.html.)
In the previously referenced LEGO example, we seem to have a violation of the Pythagorean Theorem:
72 + 112 = 49 + 121 = 170 ≠ 169 = 132The reality is that because the numbers are close enough to working out (170 is approximately 169), it is possible to slightly deform the LEGO pieces so that they fit together into what is essentially a right triangle. The goal of the exercise below is to find triples of side lengths, such as 7-11-13 that are close enough to satisfying the Pythagorean Theorem to be constructible in practice with LEGO.
Your first task is to create a Scratch program that performs computations on potential Pythagorean triples with side lengths up to 14 (the longest length between the end holes in standard LEGO beams). Use a loop to consider all possible lengths from 1 to 14 for the shortest leg, and incorporate another loop inside to consider possible lengths for the long leg. For the long leg, considers lengths from the current length of the shortest leg up to 14. The "repeat until" or "repeat" blocks in the "Control" palette should be helpful for constructing these loops.
For each combination of leg lengths as described above, compute:
You are to write all your data to a list. Lists function very much like simple variables and are created through the same "Variables" palette. Once you create a list to hold your data, you can use the "delete" block for this list near the beginning of your program to delete all the data in the list; your program can then repeatedly use the "add" block for this list to fill it with data (in a row-by-row fashion). The first thing added to your list should be just the row "Short Leg,Long Leg,Hypotenuse,Approx Hyp,Error,Abs Error,Slope" (without the quotation marks), corresponding to the data listed above that you need to compute for each combination of leg lengths. As you consider each combination of leg lengths, add a new item (row) to the list, with the leg lengths and computed values in the correct order and separated by commas (using "join" blocks from the "Operators" palette). Before adding a row of data, check that the hypotenuse and slope are in the range of interest to us: approximate hypotenuse at most 14 (so it can be realized with a single LEGO beam) and slope at most 5 (so that it is substantially more interesting than something that runs horizonatally or vertically). (The "if then" block in the "Control" palette and logic operators in the "Operators" palette should be useful for this purpose.)
Once your program is running succesfully, you will be able to store your resulting data in a file as follows. In the Stage area of your Scratch window, you will see a scrollable list headed with the name of the list where you have written your data (assuming the name of this list has been left checked in the list of lists that shows under "Make a List" when viewing the "Variables" palette). Right click (or control-click) on the name of your list in the Stage area, and select (left click) "export" from the menu that comes up. The data will store in your Downloads folder in a ".txt" file named to correspond to the name of your list. Change the file name to end in ".csv" instead of ".txt".