diff --git a/functions.py b/functions.py index de4ce4f..a1296e5 100644 --- a/functions.py +++ b/functions.py @@ -1,4 +1,26 @@ #!/usr/bin/python +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)]) + """This program uses scipy to integrate and plot the results of a basic SIR model""" @@ -8,7 +30,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 +40,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)