1. The chunk below fails with a syntax error. Fix it:
Answer:
2. Explain what the following mistery
function does:
Answer:
It receives a list of arguments and returns all of them but the first one.
3. Write a function that returns the first n
numbers in
the Fibonacci sequence:
Each number in the Fibonacci sequence is the sum of the two
previous numbers. Hint: use an auxiliary function that uses
the same trick as the range
function in the lecture notes
for class 3.
Answer:
4. Write a function that takes as arguments the coeficients
of a polynomial, and returns a function that evaluates the polynomial
for some x
:
Answer:
5. The triangular numbers
are a famous integer sequence. The first triangular number is 1. The nth
triangular number can be found by taking the previous number and adding n
(1, 3, 6, 10, 15, …). Write a closure iterator for the triangular numbers:
Answer: