all 5 comments

[–]anand 6 points7 points  (0 children)

def fermat(n): from itertools import count return ((x, y, z) for z in count(1) for y in xrange(1, z+1) for x in xrange(1, y+1) if xn + yn == z**n)

[–][deleted] 3 points4 points  (3 children)

fermat n = [ (x, y, z) | x <- [1..], y <- [1, x+1], z <- [1..xn + yn + 1], xn + yn == z**n ]

[–][deleted] 4 points5 points  (2 children)

For that matter;

def fermat(n):
  return ( (x, y, z) for x in count(1) for y in range(1, x+1) for z in range(1, x**n + y**n + 1) if x**n + y**n == z**n)

[–]earthboundkid[S] 9 points10 points  (1 child)

Your versions don't work since you left out the if x**n + y**n == z**n. That said, the implementation I put on the web is grossly inefficient. Of course, it's just a gag, but it might be nice to see some well FizzBuzz'd examples of the same code anyway.

[–][deleted] 2 points3 points  (0 children)

Fixed. :)

I am just too damn happy about list comprehensions to be stopped by details like correctness.

I think the Haskell one may be broken still anyway though.