Homework 2: Several Little Mysteries

Due: Tuesday September 17 2019, 9:00PM.

Detective Snake

Handin

After completing the homework, you will submit:

If you are using late days, make sure to make a note of that in your readme. Remember, you may only use a maximum of 3 late days per assignment. If the assignment is late (and you do NOT have anymore late days) no credit will be given.

Setup

You will need a text editor to edit your README. Link to template provided above. Any text editor is fine, and your laptop should already have one (TextEdit on Mac, NotePad on Windows). You could also install a more powerful text editor (such as Atom, instructions here), but this is not required. If you are still having a hard time, come to hours or post on Campuswire!

Helpful Things

Documentation

Useful Functions

The Assignment

More Images

Someone left some clues at the detective station but Detective Pikachu and Velma lost the clues. From memory, they remember it looking like these two pictures:

Picture One
Picture One

Picture Two
Picture Two

They have asked you to recreate it so they can show it to the other folks at the station. Fill in the functions such that the functions:

Major hint:

We have left an example in the stencil code to help you think about how to structure your code and recreate the picture. To build the lollipop example, try breaking the whole image into smaller chunks.
Suppose we had to create the lollipop. We see that there is some circular portion, which is supposed to represent the candy part, and there is a rectangle shape, which is supposed to represent the handle. So, we can break this problem into two parts. The candy part and the handle part. Once creating each lollipop piece, we can put it together. I recommend using the overlay function, which will allow you to place shapes on top of each other.

Lollipop

(Optional) Those images from above (picture one and two) are supposed to represent pictograms. Can you guess what they are supposed to represent?

A Series of Doors and Locks

Velma and Detective Pikachu need to get to their next destination. In order to get to their next destination, they must fix a series of doors that are blocking their way. Currently the doors never open. However, each door should only open in certain instances.

The doors are represented as functions. These functions will take in Boolean inputs, and depending on those inputs, will either open or close. When a function returns true, the door is opened. When a function returns false, a door is not opened. Help Velma and Detective Pikachu fix the doors!

Here are two examples:

# This door should always open, regardless of the input. 
# Do you see why?
  
fun door-a(input :: Boolean) -> Boolean:
    true
end

# This door will only open if the input is true, if the input 
# is not true, then it will return false and will not open. 
  
fun door-b(input :: Boolean) -> Boolean: 
    input
end

Open doors-and-locks.arr using the link above, and get each door to work.

Here is a quick summary of what each door should and shouldn’t do:

Advice: We’ve provided some test cases, but they are not exhaustive. We encourage you to add more so you gain a better understanding of output you are expecting. Adding additional test cases is optional, you will not be graded on what test cases you add for this problem.

Mystery Scene

As a gesture of gratitude for fixing the doors and mystery functions and cleaning up her code, Jennifer shares a picture of a mystery scene with you. She tells you that there were three detectives and two clues at the scene. However, the scene is represented as code.

Look at the file linked above and run the functiondraw-game-screen with a few different numerical inputs to see how it works.

include image 

finger-print-url = 'https://static01.nyt.com/images/2012/06/10/magazine/10wmt/mag-10WMT-t_CA0-jumbo.jpg'
magnifying-glass-url = 'https://image.flaticon.com/icons/png/512/63/63322.png'

s1 = image-url(finger-print-url)
s2 = image-url(magnifying-glass-url)

fun draw-game-screen(position):
  underlay-xy(
    underlay-xy(circle(180, 'solid', 'blue'), position, 500, s1),
    30, 20,
    above(
      beside(
        flip-vertical(s2),
        beside(
          rectangle(100, 1, 'solid', 'transparent'),
          flip-vertical(s2))),
      above(
        rectangle(1, 50, 'solid', 'transparent'),
        flip-vertical(s2))))
end

However, this picture script does not follow your CS111 style guide!

  1. Add a type annotation to the function.

  2. Add a docstring to the function. Good documentation includes:

    • A description of the input(s).

    • A description of the output.

    • Any restrictions on the input(s).

  3. Clean up this function; keep the same function name, draw-game-screen.
    Note: the output image does not have to be exactly the same, but it should be similar.
    Tip: Sometimes it can be very hard to read code. It can help to try changing some numbers around and seeing what effect that has.

    • Numbers used for positioning should not be hard-coded, but should be given a useful name. For example, CIRCLE-RADIUS + PADDING is clearer than 30 + 5.

    • Numbers that are based on their context should be computed based on their context. The image-width and image-height functions may be helpful for this.

    • Remove repeated computation using either helper functions or constants.

    • Rename constants if they are unclearly named.

    • Add short comments for lines that may not be intuitive.

    • When you are making constants, think about whether to put them inside or outside of the function. In general, you should only have constants inside of the function if they depend on the inputs.

      pi = 3.14
      fun area(R):
      	pi * num-sqr(R)
      end
      

      is cleaner than

      fun area(R):
      	pi = 3.14
      	pi * num-sqr(R)
      end
      

      There is no need to redefine pi every single time area is used; pi never changes.

README.txt

Fill out your README as usual, but this week there will be an additional portion, which is the ethics assignment.

Ethics Assignment

Additional responses required for this week will pertain to the ethics assignment.

Data Perspectives: Algorithmic Bias

Beyond teaching you some technical skills around computing and data, CS111 also wants to help you think about some of the broader societal issues surrounding data and computing. To this end, we will have a few short reading assignments that ask you to reflect on implications and possible principles of working with computing and data. This is the first such assignment.

We estimate this assignment will take roughly an hour.

Topic: Algorithmic Bias

You’ll put your answers in the README, clearly marking which answers belong to which questions. Your answer to each question should be a few sentences long. Your answers should be clear, concise, and demonstrate serious reflection, but there are no right or wrong answers. There will be an opportunity to discuss this topic in class.

Racial bias in algorithmic decision-making is (deservedly) getting a lot of attention. Read this Propublica article on racial bias in algorithms used for prison sentencing and recidivism. Also read this MIT Technology Review article about what causes algorithmic bias and why it’s so hard to fix.

Answer the following questions:

Grading

We will check that your responses:

Brown University CSCI 0111 (Fall 2019)
Do you have feedback? Fill out this form.