-4

This is not a homework question, I can assure you.

I'm trying to write a function that tests whether the equality a**n + b**n = c**n holds for

n∈{2,3,…,10}. And if there is a value of n for which the equality holds, the function should return the lowest such value as an int. The function should return False if the equality does not hold for any value of n in the given range.

e.g.

 print(f(3,4,5))

outputs:

2

and

print(f(1,2,3))

outputs:

False

I'd love to see the different approaches to such a question. I promise you this is not a homework question. Thanks in advance :)

James
  • 49
  • 1
  • 6
  • Woah, 3 vote downs :/ – James Apr 05 '15 at 12:30
  • 2
    I'm sure you could've reduced the vote-downs by including at least one attempt at solving this problem yourself? – Oliver W. Apr 05 '15 at 12:31
  • 3
    @James This question, as well as your previous questions, is inappropriate for this site. You are supposed to show what you have tried, not to post requests for code. Please do not post any more such requests. We do not care whether it's homework for you. It is homework for us. – Pascal Cuoq Apr 05 '15 at 12:32
  • I tried with the for loop, but couldn't really get anywhere. I'm very new to programming and was hoping to get some help here – James Apr 05 '15 at 12:33
  • Okay, from now on I'll post what I've tried. Sorry about that – James Apr 05 '15 at 12:34

1 Answers1

6

It's pretty easy due to Andrew Wiles who solved Fermat's last theorem and proved that for n > 2 there is no integer solution for a ** n + b ** n == c ** n

def f(a, b, c):
    return 2 if a * a + b * b == c * c else False
JuniorCompressor
  • 19,631
  • 4
  • 30
  • 57
  • Scrolled down hoping to find an answer like this - was not disappointed :) – Joost Apr 05 '15 at 12:51
  • +1 woah ... first I thought you didn't read the question properly(just after you posted the answer) ...came back again to give a reply and .... woah nice .. – Srinath Mandava Apr 05 '15 at 12:55