-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem11.py
63 lines (49 loc) · 1.22 KB
/
problem11.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Problem 11
#
# 215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
# What is the sum of the digits of the number 21000?
#
# @date 16/03/2012
# @author Ciarán McCann
# @website http://ciaranmccann.me/
import math
import helper
digits = []
with open("problem11.txt") as file:
data = file.readlines()
file.close()
for line in data:
lineOfDigits = []
for digit in (line.strip()).split(" "):
lineOfDigits.append(int(digit))
digits.append(lineOfDigits)
largest = 0
WIDTH = 20
HEIGHT = 20
for y in range(0, HEIGHT):
for x in range(0,WIDTH):
try:
horzontail = digits[y][x] * digits[y][x+1] * digits[y][x+2] * digits[y][x+3]
except:
pass
try:
vertical = digits[y][x] * digits[y+1][x] * digits[y+2][x] * digits[y+3][x]
except:
pass
try:
diagonalLeft = digits[y][x] * digits[y+1][x-1] * digits[y+2][x-2] * digits[y+3][x-3]
except:
pass
try:
diagonalRight = digits[y][x] * digits[y+1][x+1] * digits[y+2][x+2] * digits[y+3][x+3]
except:
pass
if horzontail > largest:
largest = horzontail
if vertical > largest:
largest = vertical
if diagonalLeft > largest:
largest = diagonalLeft
if diagonalRight > largest:
largest = diagonalRight
print(largest)