solution by Carlos Pinzón