CMU 15-112 Spring 2019: Fundamentals of Programming and Computer Science
Lab 1 (Due as part of hw1 on Sunday 20-Jan, at 5pm)




    Collaborative lab problems

    NOTE: Lab problems are collaborative. You must work on lab problems with at least one other student! However, you must follow the collaboration rules as specified by the syllabus, and you must list your collaborators in the special collaboration functions above each solution. These functions (like distanceCollaborators() ) should be modified to return a string containing all of your collaborators' andrewIDs separated by commas. If you do not list any collaborators, Autolab will not grade your solutions, and you will not get credit for these problems. If you collaborated but did not list your collaborators, you may lose points and this may be considered an academic integrity violation.

    #Here is an example collaboration function. It returns a single string. #This person lists three collaborators! def exampleCollaborators(): return "mdtaylor, krivers, acarnegie"


  1. Lab participation [5pts]
    You must attend your Friday lab session and work with at least one other student on the collaborative problems below. A TA will provide you with a link to record your attendance. Be sure not to leave before your attendance has been recorded!

  2. LAB COLLABORATIVE Code Writing: distance(x1, y1, x2, y2) [5pts]
    Write the function distance(x1,y1, x2, y2), which takes four int or float values representing two points and returns the distance between those points. You will need to use this function for the next problem!

  3. LAB COLLABORATIVE Code Writing: isRightTriangle(x1, y1, x2, y2, x3, y3) [5pts]
    Write the function isRightTriangle(x1, y1, x2, y2, x3, y3) that takes 6 int or float values that represent the vertices (x1,y1), (x2,y2), and (x3,y3) of a triangle, and returns True if that is a right triangle and False otherwise. You must also use distance(x1, y1, x2, y2) as a helper function (which you wrote in the previous problem).
    Note: You do not need to rewrite your distance function, even if your new collaboration partner wrote it a different way! As long as your functions are correct, they will behave identically.
    Note 2: Recall that we said to use math.isclose() (instead of ==) when comparing floats. Unfortunately, math.isclose apparently has incorrect behavior when comparing to 0. Therefore. we're now recommending that you use our own function, almostEqual, which you can find in the course notes.

  4. LAB COLLABORATIVE Code Writing: roundPegRectangularHole(r, w, h) and rectangularPegRoundHole(r, w, h) [10pts]
    For this problem, you will write two similar functions: roundPegRectangularHole(r, w, h) and rectangularPegRoundHole(r, w, h)
    roundPegRectangularHole(r, w, h) returns True if a round peg with radius r can pass through a rectangular hole with width w and height h, and False otherwise.
    rectangularPegRoundHole(r, w, h) returns True if a rectangular peg with width w and height h can pass through a round hole with radius r, and False otherwise.
    Don't make this problem harder than it needs to be! Assume this is a 2D problem, as shown in the diagrams below. (i.e. assume the pegs and holes are infinitely long, and don't check if 3D rotations can cram a short peg through a thin slot, etc.)

    1. A round peg of radius 1 can fit inside a square hole with side lengths of 3, so RoundPegRectangularHole(1, 3, 3) should return True!


    2. A round peg of radius 1 can also fit inside a rectangular hole with side lengths of 2 and 3 (but just barely!), so RoundPegRectangularHole(1, 2, 3) should return True. (RoundPegRectangularHole(1.1, 2, 3) would return False, though, because the radius would be too big!)


    3. A rectangular peg with side lengths of 2 can fit inside a circular hole with a radius of 1.5, so rectangularPegRoundHole(1.5, 2, 2) should return True.


    4. If the circle has a radius of 1.5 while the rectangle has side lengths of 2 and 3, both roundPegRectangularHole(1.5, 2, 3) and rectangularPegRoundHole(1.5, 2, 3) should return False. It doesn't matter which is the peg and which is the hole; neither will fit!

  5. Remember to submit your solutions to Autolab as part of hw1.py! And remember to list your collaborators in your file!

    If you finish early, consider working on the collaborative colorBlender problem from hw1!