[Shootout-list] Python Harmonic

Daniel Skiles Daniel Skiles <dskiles@gmail.com>
Tue, 22 Mar 2005 14:18:32 -0500


------=_Part_392_4575416.1111519112526
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Shorter, faster, and with a comment header

------=_Part_392_4575416.1111519112526
Content-Type: text/plain; name="harmonicfunc.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="harmonicfunc.py"

# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# contributed by Daniel Skiles

import sys

n =3D 10000000
if len(sys.argv) > 1:
    n =3D int(sys.argv[1])
print "%.9f" % (sum([1.0/x for x in xrange(1, n+1)]))

------=_Part_392_4575416.1111519112526--