-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution9-1.py
More file actions
46 lines (34 loc) · 1.01 KB
/
solution9-1.py
File metadata and controls
46 lines (34 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def isLow(row, col, input):
row_bound = len(input)
col_bound = len(input[0])
if row -1 > -1:
if input[row-1][col] <= input[row][col]:
return False
if row + 1 < row_bound:
if input[row+1][col] <= input[row][col]:
return False
if col - 1 > -1:
if input[row][col-1] <= input[row][col]:
return False
if col + 1 < col_bound:
if input[row][col+1] <= input[row][col]:
return False
return True
def main():
file = open('input9.txt', 'r')
file = file.readlines()
answer = 0
input = []
# parse input
for line in file:
curline = line.split('\n')[0]
curline = list(curline)
curline = [int(elem) for elem in curline]
input.append(curline)
for x in range(0, len(input)):
for y in range(0, len(input[0])):
if isLow(x,y, input):
print('Low Point:', input[x][y])
answer += (1 + input[x][y])
print(answer)
main()