diff --git a/8/twostar.py b/8/twostar.py new file mode 100644 index 0000000..a1d8f95 --- /dev/null +++ b/8/twostar.py @@ -0,0 +1,32 @@ +map = [] +def directionScore(x, y, tree): + score = 0 + if type(x) == range: # Horizontal + for i in x: + score += 1 + if map[y][i] >= tree: + break + elif type(y) == range: # Vertical + for i in y: + score += 1 + if map[i][x] >= tree: + break + return score + +with open("input.txt", "r") as f: + for line in f.readlines(): + map.append(list(line.strip())) +H = len(map) +W = len(map[0]) + +biggestScore = 0 +for y in range(H): + for x in range(W): + tree = map[y][x] + score = (directionScore(x, range(y-1, -1, -1), tree) * # Up + directionScore(x, range(y+1, H), tree) * # Down + directionScore(range(x-1, -1, -1), y, tree) * # Left + directionScore(range(x+1, W), y, tree)) # Right + if score > biggestScore: + biggestScore = score +print(biggestScore) \ No newline at end of file