Note: The method used below is very slow, with 1bb iterations when trying to find 1000. For a faster method see: https://gist.github.com/jmervine/b5d985398b3ca7ba16aa (~125k iterations)
A 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. Find the product abc.
From: https://github.com/Spencer-Allen/ProjectEuler/blob/master/Project_Euler_Q09.js
In all solutions, I tried to stay a true to the solution in the above.
Unsurprisingly, Go is the fastest and Node isn't that far behind. What's surprised me is how slow Ruby, Python and especially Perl were. I wasn't surprised at all at how slow PHP was.
jmervine@laptop:/tmp$ time go run p.go
0 500 500 0
200 375 425 31875000
375 200 425 31875000
500 0 500 0
real 0m2.315s
user 0m2.260s
sys 0m0.044s
# pre-compiled
jmervine@laptop:/tmp$ go build -o p_go p.go
jmervine@laptop:/tmp$ time ./p_go
0 500 500 0
200 375 425 31875000
375 200 425 31875000
500 0 500 0
real 0m1.913s
user 0m1.908s
sys 0m0.004s
jmervine@laptop:~/Development$ time java p
0 500 500 0
200 375 425 31875000
375 200 425 31875000
500 0 500 0
real 0m2.252s
user 0m2.256s
sys 0m0.016s
jmervine@laptop:/tmp$ time node p.js
0 500 500 0
200 375 425 31875000
375 200 425 31875000
500 0 500 0
real 0m9.133s
user 0m9.200s
sys 0m0.024s
jmervine@laptop:~/Development$ time ./p.out
0 500 500 0
200 375 425 31875000
375 200 425 31875000
500 0 500 0
real 0m11.029s
user 0m11.012s
sys 0m0.000s
jmervine@laptop:/tmp$ time ruby p.rb
0 500 500 0
200 375 425 31875000
375 200 425 31875000
500 0 500 0
real 6m5.558s
user 6m5.068s
sys 0m0.028s
jmervine@laptop:/tmp$ time python p.py
0 500 500 0
200 375 425 31875000
375 200 425 31875000
500 0 500 0
real 7m14.840s
user 7m14.336s
sys 0m0.008s
jmervine@laptop:/tmp$ time php p.php
0 500 500 0
200 375 425 31875000
375 200 425 31875000
500 0 500 0
real 9m28.152s
user 9m27.472s
sys 0m0.020s
jmervine@laptop:~/Development$ time perl p.pl
0 500 500 0
200 375 425 31875000
375 200 425 31875000
500 0 500 0
real 22m41.903s
user 22m39.352s
sys 0m0.356s