forked from Tecmax/JavaAndroidPractise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp045.py
More file actions
27 lines (23 loc) · 621 Bytes
/
Copy pathp045.py
File metadata and controls
27 lines (23 loc) · 621 Bytes
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
#
# Solution to Project Euler problem 45
# Copyright (c) Project Nayuki. All rights reserved.
#
# https://www.nayuki.io/page/project-euler-solutions
# https://github.com/nayuki/Project-Euler-solutions
#
def compute():
i = 286
j = 166
k = 144
while True:
triangle = i * (i + 1) // 2
pentagon = j * (j * 3 - 1) // 2
hexagon = k * (k * 2 - 1)
minimum = min(triangle, pentagon, hexagon)
if minimum == max(triangle, pentagon, hexagon):
return str(triangle)
if minimum == triangle: i += 1
if minimum == pentagon: j += 1
if minimum == hexagon : k += 1
if __name__ == "__main__":
print(compute())