From 4920126b1bae79bd5e3a58cac44b69f99bdcce16 Mon Sep 17 00:00:00 2001 From: al Date: Mon, 8 Feb 2016 13:50:06 -0700 Subject: [PATCH 1/3] Fixed functions --- point_pattern.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 9ae56ee..e37d063 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -1,4 +1,7 @@ import math # I am guessing that you will need to use the math module +import pdb + +from math import sqrt """ Below are 5 functions (we will talk about what @@ -27,7 +30,7 @@ def manhattan_distance(a, b): distance : float The Manhattan distance between the two points """ - distance = None # Add the algorithm to compute manhattan distance here + distance = sum(abs(a-b) for a,b in zip(a,b)) # Add the algorithm to compute manhattan distance here return distance @@ -49,7 +52,8 @@ def euclidean_distance(a, b): distance : float The Euclidean distance between the two points """ - distance = None # Add the euclidean distance algorithm here + # pdb.set_trace() + distance = sqrt(sum((a - b) ** 2 for a, b in zip(a, b))) # Add the euclidean distance algorithm here return distance @@ -87,8 +91,8 @@ def shift_point(point, x_shift, y_shift): x = getx(point) y = gety(point) - x_new = None # Add the logic to shift x here - y_new = None # Add the logic to shift y here + x_new = x_shift + x # Add the logic to shift x here + y_new = y_shift + y# Add the logic to shift y here return x_new, y_new @@ -109,8 +113,10 @@ def check_coincident(a, b): equal : bool Whether the points are equal """ - return None # Add the logic to check if coincident here - + if a == b: + return True + else: + return False def check_in(point, point_list): """ @@ -124,7 +130,11 @@ def check_in(point, point_list): point_list : list in the form [point, point_1, point_2, ..., point_n] """ - return None # Add the logic to check if a point is in the point list here + + if point in point_list: + return point + else: + return None # Add the logic to check if a point is in the point list here def getx(point): @@ -143,6 +153,7 @@ def getx(point): : int or float x coordinate """ + return point[0] From 5947dc788c01bc012bb2bd02d36ab11a97834be6 Mon Sep 17 00:00:00 2001 From: al Date: Mon, 8 Feb 2016 13:54:21 -0700 Subject: [PATCH 2/3] Forgot travis file --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..bef559c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +yml +language: python +python: + - "3.5" + +#command to run tests +script: nosetests \ No newline at end of file From 34f9c29166cf152877ebd2ecaa287c2f39504daf Mon Sep 17 00:00:00 2001 From: al Date: Mon, 8 Feb 2016 14:31:00 -0700 Subject: [PATCH 3/3] Formatted travis file wrong oops --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bef559c..d4d7f04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ -yml language: python python: - "3.5"