Original source at Rosetta Code: here