Teacher's Choice

The Combine Block (Teacher's Choice)

The combine block takes an operation (with two blank input slots) and a a list as input and reports a single result: the combination for all of the elements of the list when using the given operation. For example:

Image blocks need alt and title attributes. --MF


You choose the operation (with two input slots), and combine performs that operation between all the items in the input list and reports the result.

  1. Talk with Your Partner Discuss what combine does in this script:
  2. Even if there are two blanks in map, there's still only one input
  3. Make a block max of () and () that returns the larger of two inputs.
  4. Make map max over list 1 4 9 5 and combine with max (1,4,9,5). Talk with Your Partner What is going into the blank spaces for max? What seems to be going in the blanks for combine?

Ways to Think About It. When you see this:

The gray ring around the addition signals that you're going to apply the addition function to all of the elements of the list.
Mary, the semicolons in the combine page should be commas. Feel free to change, but only if we're even keeping the examples. I see "non-associative blocks" and "factorial" and know that this would be great in a mathematics course because it's so concrete—we can actually build the things we're talking about—but this is not a mathematics course. All the calculations should come in—we want this course to help kids with their mathematics, so the ideas of applying functions to numbers, building calculations that do what we want, etc., should all be there—but that notion of building calculations that we want means that we need to want them for something. They can't just be arbitrary, just as we wouldn't want them to be arbitrary in our mathematics curricula.
combine with addition (1,2,3,4)
think "I'm going to combine all the elements of {1, 2, 3, 4} using addition."
In other words, "I'm going to add up all the elements of {1, 2, 3, 4}"

Combine is used with functions that take two inputs like:
sum block product block join block join words (2 blanks) and predicate block or predicate blockor the max function that you defined above.

These operations are associative, which means that the result is the same no matter how the items are grouped. For example, (3 + 4) + 5 = 3 + (4 + 5) and join words("the cat")("sat") = join words("the")("cat sat").

  1. What happens if you drag non-associative blocks such as difference block or quotient block into combine? Try it.
  2. Moral of the story: don't use subtraction or division in combine because the grouping of the items matters in these cases. For example, (3 – 4) – 5 ≠ 3 – (4 – 5).
  3. Build a block sum that takes a list of numbers and reports their sum.
  4. Click on the script to open a new project.
    list of 2-digit numbers
    Edit the block definition for average(grades) to report the average of a list of grades. Use your block to find the average of numbers: \text{average} = \frac{\text{sum of numbers}}{\text{total number of numbers}}
  1. Talk with Your PartnerTry this experiment. Make map addition over (1,2,3,4) and combine with addition (1,2,3,4). What is going into the blank addition spaces for map? What seems to be going in the blanks for combine?
  2. Al was concerned that we removed countdown because it previewed this factorial problem. --MF
  3. Talk with Your Partner You met the factorial function before (see this example). It takes a positive integer input n and reports the product of all the positive integers between 1 and n. Make a block factorial that models this using combine.

    factorial of 5

Use this list of squares:
set (squares) to {1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225}
Which of these expressions will report a list?
Choose all that apply.

map (sqrt of()) over (squares)
keep items such that (()mod(2)=0) from (squares)
combine with (()+()) items of (squares)
keep items such that (letter (length of ()) of () = 1) from (squares)
map (()+()) over (squares)
combine with (join ()()) items of (squares)
map ((0)-()) over (squares)
map (()-()) over (squares)

Use the same list of squares:
set (squares) to {1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225}
The expressions in this problem are the same as you saw in question 1.
Which of these statements are true?
Choose all that apply.

keep items such that (()mod(2)=0) from (squares) reports a list with only even square numbers.
combine with (()+()) items of (squares) and map (()+()) over (squares) report the same result.
keep items such that ((letter (length of ()) of ())=1) from (squares) reports the list {1, 16, 100, 121, 144, 169, and 196}.
combine with (()+()) items of (squares) and combine with (join ()()) items of (squares) report the same result.
map ((0)-()) over (squares) and map (()-()) over (squares) both report a list with negative values.