Assignment #3 - Manipulation of lists using functions

Write functions/procedures to complete the tasks for manipulating lists.

Each function in this assignment will probably begin:
function_name:=proc(L)
description "this is a description";

There may be a line declaring local or global variables in your procedure.

1. A function reverse to 'reverse' the order of the list :
> reverse([4,1,2,4,3,1,5]);
    [5,1,3,4,2,1,4]


2. A function double which returns a list with each entry repeated twice :
> double([4,1,2,4,3,1,5]);
    [4,4,1,1,2,2,4,4,3,3,1,1,5,5]


3. A function add_list which returns the sum of the elements of the list :
> add_list([4,1,2,4,3,1,5]);
    20


4. A function split_list which returns a list containing two lists, with the first entry the first half of the list (or slightly more if the length of the list is odd) and the second entry is the second half in a list :
> split_list([4,1,2,4,3,1,5]);
    [[4,1,2,4],[3,1,5]]


5. A function even_positions the entries in the even positions :
> even_positions([4,1,2,4,3,1,5]);
    [1,4,1]


6. A function even_entries which returns a list of entries in in the list which are even :
> even_entries([4,1,2,4,3,1,5]);
    [4,2,4]


7. A functions sort_entries which returns a list of entries in increasing order :
> sort_entries([4,1,2,4,3,1,5]);
    [1,1,2,3,4,4,5]


8. A function remove_duplicates duplicates from the list (keeping the same order) :
> remove_duplicates([4,1,2,4,3,1,5]);
    [4,1,2,3,5]




Write your code in a worksheet. Place your name and student id number at the top. Below that I would like to see all the functions together. At the bottom of the worksheet you should give examples of how to use them all. Your assignment will be graded by replacing L by some other list of integers and seeing if what you wrote completes the given task.

Save your worksheets and upload the file to Moodle.


Here are some commands that you might want to use: Maple's help page on lists, add an element to a list, define a procedure, help on procedures, programming guide on procedures,
op, nops, seq, sort, zip, flatten, member, subsop, select, proc