So my program tries to find Pythagorean Triplet, where a^2 + b^2 = c^2
AND a+b+c=1000
. So everything works well, but program finds the answer quite early in the program runtime, so I would like to break somehow out of all the loops. I am trying simple boolean method, but for some reason my cycle stops after 1 second. If I remove exit = True
then everything works (but no break obviously).
P.s. it's also same problem if I use simple 0
or 1
integers to check that.
Can anyone give me ideas why this is not working?
i = 0
j = 0
k = 0
exit = False
while (i < 999 and exit == False):
while (j < 999 and exit == False):
while (k < 999 and exit == False):
if i*i + j*j == k*k:
if i + j + k == 1000:
exit = True
ii = i
jj = j
kk = k
k += 1
j += 1
k = 1
i += 1
j = 1
i = 1
print('result: %d^2 + %d^2 = %d^2' % (ii, jj, kk))