Skip to content

Instantly share code, notes, and snippets.

@0xKD
Created March 9, 2016 16:17
Show Gist options
  • Save 0xKD/b62aaadf0cfd5eaf0bda to your computer and use it in GitHub Desktop.
Save 0xKD/b62aaadf0cfd5eaf0bda to your computer and use it in GitHub Desktop.
Sum of Diagonals
"""
73 74 75 76 77 78 79 80 81
72 43 44 45 46 47 48 49 50
71 42 21 22 23 24 25 26 51
70 41 20 7 8 9 10 27 52
69 40 19 6 1 2 11 28 53
68 39 18 5 4 3 12 29 54
67 38 17 16 15 14 13 30 55
66 37 36 35 34 33 32 31 56
65 64 63 62 61 60 59 58 57
"""
size = 1001
ia, ib, ic, id = 10, 12, 14, 16
a, b, c, d = 3, 5, 7, 9
s = 1
for i in range(0, size // 2):
s += sum([a, b, c, d])
a, b, c, d = a + ia, b + ib, c + ic, d + id
ia, ib, ic, id = ia + 8, ib + 8, ic + 8, id + 8
print(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment