''' Homework 3
-- Due Sunday, Feb 14th at 11:59pm
-- Always write the final code yourself
-- Never use a library function that solves the problem
-- If you collaborated with a peer, mention them
-- Cite any websites you referenced
-- Use the PEP-8 checker for full style points:
https://pypi.python.org/pypi/pep8
'''
from __future__ import absolute_import, division, print_function
def norm(x, y, *args, **kwargs):
''' x, y and additional unnamed arguments represent a vector.
Find the length of the vector.
An optional argument "p" specifies which p-norm to use, you should
default to the 2-norm (Euclidean length).
(https://en.wikipedia.org/wiki/Norm_%28mathematics%29#p-norm)
'''
pass
def choose(n, k, cache={}):
''' Pascal's Rule says that for any 1 <= k <= n
n choose k = [(n - 1) choose k] + [(n-1) choose (k-1)].
Use this equality to implement the choose function,
using memoization to avoid exponential running time.
(You can assume that 1 <= k <= n for the inputs.)
'''
pass
"""
Solve all the following problems by writing a single line of code
in the functional programming style.
You may include stylistic linebreaks by writing a backslash \.
"""
def reverse(li):
''' Return a list with the elements of li in reverse order.'''
pass
def palindrome(li):
''' Return True if li is a palindrome else return False. '''
pass
def product_over(li, k):
''' Compute the product of all the elements in the list greater than k.'''
pass
def merge(li1, li2):
''' Takes two sorted lists and merges them in sorted order. '''
pass
def msort(li):
''' Mergesorts two lists using the merge function above '''
pass
''' Below, modify your merge and mergesort to take in a comparator.
The comparator should be a function from two objects of the
type of the list's elements, and return -1 (less than), 0 (equal) or
1 (greater than).
The default comparator (a lambda) should behave identically to the
standard mergesort. '''
def merge_c(li1, li2, comp=None):
pass
def msort_c(li1, li2, comp=None):
pass
def norm_sort(li):
''' Write a function to order vectors in li by their 1-norms, in increasing
order. It should use the msort_c defined above.'''
pass
def main():
pass
if __name__ == "__main__":
main()