c01 · E1

Practise: Rules That Turn Inputs Into Outputs

c01.E1.1E1 · numeric

A square-root procedure states one line of its contract: for a whole number from 2 to 20 it returns an estimate with , and it promises nothing about exactness. A caller passes and receives . Compute the residual . The contract's second line is met exactly when that residual is below 0.01.

c01.E1.2E1 · numeric

A recorder timed five tasks and wrote down whole minutes. The table holds the readings. A candidate rule called round down divides the elapsed seconds by sixty and keeps the whole part. The scorer charges 0 when the rule and the notebook agree and 1 when they disagree, then divides the total charge by the number of rows.

| item | 1 | 2 | 3 | 4 | 5 | |---|---|---|---|---|---| | seconds | 50 | 70 | 130 | 185 | 300 | | minutes written | 1 | 1 | 2 | 3 | 5 |

Score round down on these five rows. Give the score as a fraction of one.

c01.E1.3E1 · numeric

The tower of Hanoi recurrence is with , where counts the moves needed for disks. Section 1.2 lists the first values 0, 1, 3, 7, 15 and 31. Give .

c01.E1.4E1 · numeric

A delegating program totals four readings, 3, 9, 4 and 8. Substitution gives the nest , and the additions run from the innermost bracket outward. What number does the third addition produce?

c01.E1.5E1 · numeric

The summation template of section 1.3 takes two slots: one for the term to add and one for the next value. Fill the term slot with the cubing function, so the term at is , and the next slot with "add one". Run the template from 1 to 5 inclusive. Give the total.

c01.E1.6E1 · numeric

A pair is built from 4 and 11 by the procedure method of section 1.5. The constructor receives the two objects and returns a procedure that answers 0 with the first object and 1 with the second. The first selector applies that returned procedure to 0, and the second selector applies it to 1. What does the second selector return?

c01.E1.7E1 · numeric

A table is stored as two columns: the elapsed seconds are and the recorded minutes are . A scorer loops over the table with "for row in table", reads row[0] as the elapsed time and row[1] as the recorded answer, and charges the candidate against row[1]. Handed the pair of columns, the first row the loop sees is the seconds column. What number does it charge as the recorded answer for the first item?

c01.E1.8E1 · choice

A procedure states four lines. It takes a non-empty list of whole numbers. It returns their sum. It leaves the list unchanged. It promises nothing about lists that contain a negative number. Which single check tests the third line, "what stays the same"?

A. Call it with [] and expect a refusal. B. Call it with [1, 2, 3] and expect 6. C. Copy the list, call the procedure, then compare the list with the copy. D. Call it with [-1] and record what happens.

Choose one answer

Other tiers

E2 Derive · E3 Open

Every hint opened, solution viewed and answer checked is recorded in this browser only. See Progress to export or delete it.