-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp044.py
29 lines (24 loc) · 951 Bytes
/
p044.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
# Copyright (c) Hoshmand. All rights reserved.
#
# https://twitter.com/hoshmandctf
# https://github.com/hoshmandctf
def generate_pentagonal_numbers(limit):
pentagonals = set()
for n in range(1, limit + 1):
pentagonal = n * (3 * n - 1) // 2
pentagonals.add(pentagonal)
return pentagonals
def find_minimized_pentagonal_difference():
limit = 3000
pentagonals = generate_pentagonal_numbers(limit)
min_difference = float('inf')
for pj in pentagonals:
for pk in pentagonals:
if pj != pk:
if pj + pk in pentagonals and abs(pk - pj) in pentagonals:
difference = abs(pk - pj)
if difference < min_difference:
min_difference = difference
return min_difference
result = find_minimized_pentagonal_difference()
print("The value of D for the pair of pentagonal numbers is:", result)