lastname
with your last name and firstname
with your first name: [cse341-hw2-lastname-firstname]
. If you email me more than once, the last email I recieve BEFORE class at 9:30 am will be the one I will look at.For each of the following functions, do the following:
* E.g., "fun divide (x) = x /
3.0
is of type fn : real -> real
, x must
be a real since the / operator takes only arguments of type
real, and the function returns a real because the return type
of the / operator is a real."
fun hello(n) = n
fun we (x,y,z) = {me = x::nil, you = y, them = (fn z => z ^ " who")};
fun fire(a,b,c::d) = [a,b] :: c;
fun foobar _ a b nil = {c=a::b, d=nil} | foobar p q r (x::xs) = let val s = p::xs val t = [r] in {c=s, d=t} end;
fun pow3 0 = 1 | pow3 n = 3 * pow3(n-1);
foldl
, as previous versions of this assignment
demanded.UPDATE: This question has been changed, to ask you to find 20 instead of 50 Fibonacci numbers; also, a fourth subquestion has been added..
Using the function you wrote above, find the first 20 Fibonacci numbers and do the following:
map
function to get
a list of the square of each of the Fibonacci numbers, (e.g. 0
1 1 4 9 25)filter
function to
get a list of all the odd numbers of this these squared
Fibonacci numbers.find
function to
find the smallest squared Fibonacci number divisble by 5 and
greater than 1000.foldl
function to
compute, for each element ei in a list, the
cumulative sum of all elements e1 through
ei in the list. The list of cumulative sums for
each position should be returned. For example, given the list
[1, 2, 4, 8]
, your function should return
[1, 3, 7, 15]
(because 3 = 1 + 2, 7 = 1 + 2 + 4,
and 15 = 1 + 2 + 4 + 8).