Advertisement
StephenLujan

perfect cubes

Jun 13th, 2016
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import math;
  2.  
  3. MAX = 30
  4. MIN = -30
  5.  
  6. def is_perfect_cube(num):
  7.     num = math.fabs(num)
  8.     if math.pow(num, 1 / 3) == int(math.pow(num, 1 / 3)):
  9.         return True;
  10.     return False;
  11.  
  12.  
  13. def cubes_test(a, b, c, d):
  14.     for num in [a + b, b + c, c + d, a + b + c, b + c + d, a + b + c + d]:
  15.         if not is_perfect_cube(num):
  16.             return False
  17.     if len(set([a, b, c, d])) < 4:
  18.         return False
  19.     #print("found combo:", a, b, c, d)
  20.     print ((a, b, c, d))
  21.     return True
  22.  
  23.  
  24. def main():
  25.     for a in range(MIN, MAX):
  26.         #print(a)
  27.         for b in range(MIN, MAX):
  28.             for c in range(MIN, MAX):
  29.                 for d in range(MIN, MAX):
  30.                     cubes_test(a, b, c, d)
  31.  
  32. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement