-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum_of_cubes.py
More file actions
27 lines (25 loc) · 822 Bytes
/
sum_of_cubes.py
File metadata and controls
27 lines (25 loc) · 822 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
"""
Page 79 - Cracking the coding interview
Print all positive integer solutions to the equation a^3 + b^3 = c^3 + d^3, where a, b, c
and d are integers between 1 and 1000.
"""
def findSumOfCubes():
data = {}
for i in range(1, 1001):
for j in range(1, 1001):
result = i**3 + j**3
if result in data:
data[result].append((i, j))
else:
data[result] = [(i, j)]
return data
if __name__ == "__main__":
result = findSumOfCubes()
count = 0
for key, value in result.items():
for val1 in value:
for val2 in value:
if val1[0] != val2[1] and val1[1] != val2[0] and val1[0] != val2[0] and val1[1] != val2[1]:
# print(val1, val2)
count += 1
print(count)