Advanced Programming, Jan-Apr 2015 Assignment 1, due 18 Jan 2015 ---------------------------------------------------------------------- Instructions: 1. For each question, write a separate Python program with the filename indicated in the question. Zip your solutions into a single archive. Use your CMI username to name the zip file (e.g. "madhavan.zip") and submit the zip file via moodle. If you don't name your zip file or the enclosed Python file correctly, you risk losing marks. 2. If the question asks for a function, you *must* write a function in Python (i.e., def f(x): ... ) Ensure that the function you define has the name indicated in the question. Also ensure that your function returns the value asked for, rather than printing it. If you add code to your file to test your function, make sure you *remove* this code when you submit your solution. The Python file you submit should have *only* the function definition. ---------------------------------------------------------------------- 1. Filename: primes.py Write a Python function "primes" such that primes(n) returns the list of primes less than or equal to n, in ascending order. 2. Filename: nthprime.py Write a Python function "nthprime" such that nthprime(k) computes the k-th prime in the sequence {2,3,5,7,11,...}, starting with index 0. For instance nthprime(1) should return 3, nthprime(5) should return 13 etc. 3. Filename: sqroot.py Write a function to compute (positive) square roots upto a given accuracy using binary search. Given x, not necessarily an integer, and a tolerance delta, the initial interval for the square root of x is [0..1] if x < 1 and [0..x] if x >= 1. Start with an estimate e = x/2 for the square root of x. Repeatedly halve the interval, as appropriate, until |x - e**2| <= delta. You may assume that x > 0 and delta > 0. Your function should be called "sqroot" and should take two parameters, x and delta, in that order. 4, Filename: overlap.py Write a function "overlap" that takes two lists of integers and returns the number of distinct values that occur in both lists. For instance; - overlap([1,3,4,7],[9,13,7,5,1,2]) should return 2 ("1" and "7" are common) - overlap([2,3,2,1],[4,2,5,2]) should return 1 (the value "2" is common, ignoring multiplicites) Hint: Python has a built-in sort function for lists. ----------------------------------------------------------------------