Optional Page

Composition of Functions (Optional)

Cut from U1:

Debugging can be a pain. Here are some tips for writing code without (or with fewer) bugs:

  1. Start Small: Build one (small) part of your program and get it working right before moving on to the next piece.
  2. Keep it Working: When you build the next piece, get that new piece working before you move on again.

This approach is nice because you won't have a huge mess with many bugs to sort out and you'll have something that works to share with your teacher and other programmers at every step of the way.

Here is one way to define max of () and () and ():

Script for 'max' with three arguments

Figure out how to make the following blocks.

  1. A three-input addition operator that accepts only numbers.

    Three-argument addition operator
  2. A reporter block named "sum of two smallest" that takes three numbers as inputs, and reports the sum of the two smallest (the example shown below would report 9):

    sum of two smallest block
  3. A predicate block named "Are any equal?" that compares 3 numbers and returns true if any two are equal to each other (the example shown below would return true):

    Are any equal? predicate block
  1. Picture in your head (or sketch if you prefer): Is it possible to build a triangle from three rods of length 6", 5", and 7"?
  2. What about three rods of lengths 2", 10", and 4"?
  3. What about three rods of lengths 6", 6", and 12"?
  4. Find a way to use max of () and () and () and sum of two smallest block to build the predicate block can-a-triangle-be-made-using-these-three-lengths