Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pprint
- heightMap = []
- lowPoints = []
- def getHeight(aRow, aCol, aDirection):
- if aDirection == 'N':
- if aRow == 0:
- return 99
- else:
- return heightMap[aRow - 1][aCol]
- elif aDirection == 'S':
- if aRow == len(heightMap) - 1:
- return 99
- else:
- return heightMap[aRow + 1][aCol]
- elif aDirection == 'E':
- if aCol == len(heightMap[0]) - 1:
- return 99
- else:
- return heightMap[aRow][aCol + 1]
- elif aDirection == 'W':
- if aCol == 0:
- return 99
- else:
- return heightMap[aRow][aCol - 1]
- else:
- assert False, 'This is embarrassing. How did I get here?'
- assert False, 'Should not be possible to get here'
- def initHeightMap(aHeightMap):
- with open('scratch.txt') as INFILE:
- for LINE in INFILE:
- LINE = LINE.rstrip()
- row = [int(x) for x in list(LINE)]
- aHeightMap.append(row)
- initHeightMap(heightMap)
- for row in range(len(heightMap)):
- for col in range(len(heightMap[0])):
- n = getHeight(row, col, 'N')
- s = getHeight(row, col, 'S')
- e = getHeight(row, col, 'E')
- w = getHeight(row, col, 'W')
- currentHeight = heightMap[row][col]
- if currentHeight < n and currentHeight < s and currentHeight < e and currentHeight < w:
- lowPoints.append((row, col))
- print(lowPoints)
- sumRiskLevels = 0
- for lowPoint in lowPoints:
- riskLevel = heightMap[lowPoint[0]][lowPoint[1]]
- riskLevel +=1
- sumRiskLevels += riskLevel
- print(f'{sumRiskLevels=}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement