Math/CSE 1560 Lab 7
Exercise: Writing while and for-loops in Maple
Objective
The objective of this exercise is to test your familiarity with solving problems
using while and 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 printout
s will be accepted.
Starting off:
- Open Maple 12 by clicking on the icon marked as such. If Maple does
not start, let the TA know immediately. If asked, choose to start a new workshe
et.
- On the first 2 lines, enter your name and student number as
comments -- start the lines with character #. Then save the file as
`lab7.mw` by clicking on `File` and then `save as`.
Problems
Note: Some of these problems can be solved using seq() or map(), For this assign
ment you must use for-loops instead.
- (4 points) Mersenne primes: A Mersenne prime is a number that is prime and of the form 2^p -1 where p is a prime. E.g. 7 is a Mersenne prime because 7=2^3 -1, and 3 is a prime.
Write a procedure that takes a positive integer n as input and returns all Mersenne primes less than or equal to n.
- (4 points)
Perfect numbers: A number is defined to be perfect if it is equal to the sum of all its factors less than itself. E.g. 6 is a perfect number because its factors less than itself are 1,2,3 and 1+2+3=6.
Write a procedure that takes a positive integer n as input and returns all perfect numbers less than or equal to n. Feel free to use the solutions to previous assignments/exams (for finding lists of factors), but you may not use commands not covered in class.
- (5 points)
Write a procedure that takes a list with positive integers between 1 and
100 and returns a list of size 10 containing the counts in the ranges 1-10,11-2
0,21-30,..,91-100.
For example, when called on the list [11,21,31,41,51,53] it should return
[0,1,1,1,1,2,0,0,0,0]. Feel free to use the ceil function in this question.
- (4 points)
Write a procedure that takes as input a list and returns a list that is formed by making 2 copies of every element. For example if the input is [2,2,3,4] the output should be [2,2,2,2,3,3,4,4].
- (3 points) Write a procedure that takes as input a list of single digits (unsigned) and returns the integer by interpreting the list as digits of an
integer. E.g. If the input is [1,0,1,3], the number returned should be 1013.
Final steps
- Save your worksheet.
- Submit the assignment as lab 7 in Moodle (the URL is moodle.math.yo
rku.ca). You can upload several times, but remember to submit using the "send fo
r marking" at the end ONCE - otherwise it may not be sent.
- You are done with this assignment. Remember to logout before you le
ave the lab.