We should change the CSS so that sidenotes never extend behind the element they are about; add space to the element if necessary. For example, that "Read this out loud" box shouldn't overlap the orange. --MF, 12/27/17
Brian also wants to change the katex in 5 and make the narrower box light blue here. --MF, 12/27/17
In this lab, you will learn that some ways to solve a problem are faster than others.
On this page, you will compare two algorithms for adding the numbers from 1 to an input number (as shown below).
combine
to add up the list.
The block takes an operation (with two blank input slots) and a list as input, and it reports a single result (not a list): the combination of the elements in the list when using the given operation. For example:
Combine
is a higher order function. This means that it is a function that takes a function as input. You've seen several higher order functions already: for each
(in Unit 2 Lab 2), keep
(in Unit 2 Lab 3), and map
(in Unit 3 Lab 1).You choose the operation, and combine
performs that operation by combining all the items in the input list and then reports the result.
Notice that the function used to combine the list items always has two blank input slots. Both map
and keep
only need one blank in their input function, but with combine
, two are required.
map
and keep
, combine
is mostly used with one of only these six functions:1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | |
+ | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 |
numbers from () to ()
in the Variables palette. You'll need to to see it.sum from 1 to
algorithm. You can use Alphie’s method (using combine
to code sum
), you can use Betsy’s formula, or you can build it your own way.sum from 1 to(
x)
.