From 7d18e8679707097785b946dc602722b81e1a1c35 Mon Sep 17 00:00:00 2001 From: Jake Date: Sun, 12 Dec 2021 18:18:13 +0000 Subject: [PATCH] Completed day 9, task 1 --- Day-9/day9-1.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Day-9/day9-1.py diff --git a/Day-9/day9-1.py b/Day-9/day9-1.py new file mode 100644 index 0000000..8110f36 --- /dev/null +++ b/Day-9/day9-1.py @@ -0,0 +1,31 @@ +#!/usr/bin/python3 + +sumOfLowest = 0 +map = [] + +def checkSurrounding(list, x, y): + possibleX = [x, x-1, x+1] + possibleY = [y, y-1, y+1] + + for newY in possibleY: + if(newY < 0 or newY >= len(list)): + continue + for newX in possibleX: + if(newX < 0 or newX >= len(list[0])): + continue + if(list[y][x] > list[newY][newX]): + return False + return True + +with open('/home/jake/Documents/AoC-2021/Day-9/input.txt') as inputFile: + for line in inputFile: + lineList = list(line.strip('\n')) + lineList = [int(x) for x in lineList] + map.append(lineList) + +for x in range(len(map[0])): + for y in range(len(map)): + if(checkSurrounding(map, x, y)): + sumOfLowest += (map[y][x] + 1) + +print("Sum of risk levels is: " + str(sumOfLowest)) \ No newline at end of file