Skip to content

Commit 972dff8

Browse files
committed
5-Makefile
1 parent a45d9d6 commit 972dff8

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

Diff for: 0x1C-makefiles/5-island_perimeter.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/python3
2+
"""Defines an island perimeter measuring function."""
3+
4+
5+
def island_perimeter(grid):
6+
"""Return the perimiter of an island.
7+
8+
The grid represents water by 0 and land by 1.
9+
10+
Args:
11+
grid (list): A list of list of integers representing an island.
12+
Returns:
13+
The perimeter of the island defined in grid.
14+
"""
15+
width = len(grid[0])
16+
height = len(grid)
17+
edges = 0
18+
size = 0
19+
20+
for i in range(height):
21+
for j in range(width):
22+
if grid[i][j] == 1:
23+
size += 1
24+
if (j > 0 and grid[i][j - 1] == 1):
25+
edges += 1
26+
if (i > 0 and grid[i - 1][j] == 1):
27+
edges += 1
28+
return size * 4 - edges * 2

Diff for: 0x1C-makefiles/main.o

-1.51 KB
Binary file not shown.

Diff for: 0x1C-makefiles/school

-16.4 KB
Binary file not shown.

Diff for: 0x1C-makefiles/school.o

-4.02 KB
Binary file not shown.

0 commit comments

Comments
 (0)