Math/CSE 1560 Lab 8
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 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.
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 worksheet.
- On the first 2 lines, enter your name and student number as
comments -- start the lines with character #. Then save the file as
`lab8.mw` by clicking on `File` and then `save as`.
Problems
Note: Some of these problems can be solved using seq() or map(), For this assignment you must use for-loops instead.
- (5 points) Goldbach Conjecture: This conjecture states that
every even integer greater than 2 be written as the sum of two primes. This conjecture has not been proved or disproved and is a famous, longstanding open problem in Mathematics.
Write a procedure that takes as input a postive integer and returns an
error message if the input is odd; otherwise it computes one possible way to write the integer as a sum of two primes, and returns a list containing these 2 primes.
- (5 points) Prime quadruplets: A prime quadruplet is a set of four primes of the form {p, p+2, p+6, p+8}. Write a procedure PrimeQuad(n) that takes a
positive integer n as input and prints all prime quadruplets whose smallest number is less than or equal to n.
For example, PrimeQuad(20) should print
5, 7, 11, 13
11, 13, 17, 19
- (5 points)
Write a procedure that takes as input a positive integer n and returns
true if n=a^a for some positive integer a, and false otherwise.
- (5 points)
Write a procedure that takes as input a list of integers L and returns a list of
the indices of the elements in L[1..k] that are equal to the mean of the list.
E.g. if L=[12,3,2,8,1], the procedure should return [] (the mean is 5.2 and there is no element equal to 5.2 in the list. If L=[2,3,4,2,4,3], the procedure
should return the list [2,6], because the mean of the elements of L is 3 and
the second and sixth elements of L are 3.
Final steps
- Save your worksheet.
- Submit the assignment as lab 8 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.