FriendsBlog Archive
|
The beauty of the functional programmingA Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000.
#!/bin/env python
import sys import cmath def product (a, b, c): print a * b * c sys.exit () c = lambda a, b: abs (cmath.sqrt (a<strong>2 + b</strong>2)) f = lambda a, b, c: c % 1 == 0 and a + b + c == 1000 g = lambda a, b, c: f (a, b, c) and product (a, b, c) [ (a, b) for a in xrange (1, 1000) for b in xrange (a + 1, 1000) if g (a, b, c (a, b)) ]
Trackback URI: http://www.ceyusa.com/blog/index.php/trackback/517
#1 Re: The beauty of the functional programming#!/usr/bin/perl -w [ Reply (0) ]
Leave a Comment
Comment XML feeds: RSS | Atom
|
Recent Comments On Blog