CS 112: Trial Handson Exam

Choose TWO out of the following three problems.
  1. Write a lastelements function that takes a single list (containing lists) and returns a list containing all the last elements of the lists in its argument. For example:
    ( lastelements '((1 2 3) (a b c) (x y z) (4 4 4 4)) ) => (3 c z 4)
    ( lastelements '((5) (hi (there))) ) => (5 (there))
    
  2. Write a sumodds function that takes a list of numbers and returns the sum of all odd numbers in the list (note: (mod x y) returns the remainder after an integer division of x and y). For example:
    ( sumodds '(1 2 3 4 5) ) => 9
    ( sumodds '(1 4 3 44 143 4414 34) ) => 147
    
  3. Write a sandwich function that takes a list of lists. Each of the inner lists contains two symbols. The function returns a list containing all the first elements in order followed by all the last elements in reverse order. The elements of the first list "sandwich" the remaining lists. For example:
    ( sandwich '((a b) (3 4) (x y) (z z)) ) => (a 3 x z z y 4 b)
    ( sandwich '((this ever) (is function) (the coolest)) ) => (this is the coolest function ever)
    ( sandwich '((to divine) (loop recurse) (is to) (human -)) ) => (to loop is human - to recurse divine)