Math/CSE 1560 Lab 6
Exercise: Writing for-loops in Maple
Objective
The objective of this exercise is to test your familiarity with solving problems using for-loops in Maple.
Grading
This lab exercise is worth 10% of the course. It is meant to be completed in the
lab, individually (Collaboration is NOT allowed for this exercise).
NOTE: This is a 2 hour lab. The submission server will close shortly after 4:30 pm. You will not be able to submit your work after that time. No printouts will be accepted.
Problems
Note: Some of these problems can be solved using seq() or map(), For this assignment you must use for-loops instead.
- (4 points)
Write a procedure that takes a list and returns a list containing the even numbered elements of the list given. For example, when called on the list
[1,2,3,4,5] it should return [2,4].
Test your program with an odd length list and an even length list.
- (4 points) Write a procedure that takes a list of numbers and returns a list of indices i satisfying L[i]> 2*L[i-1].
- (4 points) Write a procedure that takes as input a list. If the list is of odd length, it should print an error message and return an empty list.
If the list is of even length, then it should return a new list formed by concatenating the list of odd (index) elements, followed by the list of even (index) elements. Thus
if the input is [10,20,30,40,50,60] then the output should be [10,30,50,20,40,60].
- (4 points) Let us define a list to be square if it is of even kength and the first half is identical to the second half. For exmple [1,2,1,2] is a square list but [1,2,3,1,2] is not. Write a procedure that takes a list and returns true if the list is square and false otherwise. You should not use seq() or an additional list.
- (4 points) Write a procedure that takes a list of integers and returns the sum of all elements in the list that are not prime numbers.
For example, when called on the list [11,21,31,42] it should return 63.
Final steps
- Save your worksheet.
- Submit the assignment as lab 6 in Moodle (the URL is moodle.math.yorku.ca). You can upload several times, but remember to submit using the "send for marking" at the end ONCE - otherwise it may not be sent.
- You are done with this assignment. Remember to logout before you leave the lab.