--oyUTqETQ0mS9luUI
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Thu, Dec 15, 2005 at 04:27:08AM +0900, Christian Neukirchen wrote:
> def fib(n)
>   (1..n-2).inject([1, 1]) { |(a, b), n| [b, a+b] }.last
> end

If we're talking about elegance, I prefer this one.  It reads just
like the definition of the sequence:

def fib(n)
    n > 1 ? fib(n-1) + fib(n-2) : n
end

You can even make it run efficiently by memoizing it.  :-)

-Ed

--oyUTqETQ0mS9luUI
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDoHkLnhUz11p9MSARAtPIAJ9MG0Y4b3IxEXLaaGXZ1pMYjncXgACcDoOr
jrIFC+o2pdgjSKKVuEFOXgkpw
-----END PGP SIGNATURE-----

--oyUTqETQ0mS9luUI--