From 736f12a9d48a82f60bfe8185e0ab0ebf5eef0195 Mon Sep 17 00:00:00 2001 From: Peyton Rose Date: Tue, 4 Apr 2017 11:14:17 -0700 Subject: [PATCH 1/2] adding the soltion to today's leetcode challenge --- functions.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/functions.py b/functions.py index e69de29..d23e718 100644 --- a/functions.py +++ b/functions.py @@ -0,0 +1,21 @@ +def islandPerimeter(grid): + """ + The solution to today's leetcode challenge. + :type grid: List[List[int]] + :rtype: int + """ + + leni = len(grid) + lenj = len(grid[0]) + + def countCell(i,j): + if not grid[i][j]: + return 0 + borders = 4 + if i>0 and grid[i-1][j]: borders -= 1 + if i<(leni-1) and grid[i+1][j]: borders -= 1 + if j<(lenj-1) and grid[i][j+1]: borders -= 1 + if j>0 and grid[i][j-1]: borders -= 1 + return borders + + return sum([countCell(i,j) for i in range(leni) for j in range(lenj)]) From db82986728ee263c5d6ace4c2cdbb5d38be09caa Mon Sep 17 00:00:00 2001 From: Kelly Anne Pierce Date: Tue, 4 Apr 2017 11:26:51 -0700 Subject: [PATCH 2/2] fixed variable case --- functions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions.py b/functions.py index de4ce4f..c112ea7 100644 --- a/functions.py +++ b/functions.py @@ -8,7 +8,7 @@ from pylab import * #Define Constants -Beta=2.0 +beta=2.0 gamma=.8 init=array([0.95,0.05,0.0]) finalTime=20.0 @@ -18,8 +18,8 @@ def derv(x,t): """Computes the derv operator for the basic sir model""" y=zeros(3); - y[0]=-Beta*x[0]*x[1] - y[1]=Beta*x[0]*x[1]-gamma*x[1] + y[0]=-beta*x[0]*x[1] + y[1]=beta*x[0]*x[1]-gamma*x[1] y[2]=gamma*x[1] return(y)