[Vit-discuss] Top Ruby Projects algorithm?

zdennis zdennis at mktec.com
Fri Aug 25 16:14:20 EDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Todd Willey wrote:
> On 8/25/06, Martin DeMello <martindemello at gmail.com> wrote:
>> On 8/26/06, James Edward Gray II <james at grayproductions.net> wrote:
>>> On Aug 25, 2006, at 2:37 PM, Martin DeMello wrote:
>>>
>>>> On 8/26/06, John W. Long <ng at johnwlong.com> wrote:
>>>>> Suggestions?
>>>> a = "Goodbye cruel world"
>>>> a["Goodbye cruel"] = "Hello"
>>>> puts a
>>> But isn't that just what we already have?
>> Oops - missed that. Sorry for the noise.
>>
>> a = 1
>> 2.upto(1000) {|i| a = a * i}
>> puts a
> 
> why not:
> puts (2...1000).inject(1){|fact,current| fact * current}

I would be explicit if this goes on the site. fact => factorial, and make it span two lines if it gets too long. I think it makes
it more readable to what the code is doing, and it leads people in the direction of determining the cleverness of the code.

Zach
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFE71ocMyx0fW1d8G0RAo5fAJ9Rz1Ozw+JCFZy9VCshYQtXdpNc8gCff5My
0L1VyNhhc+KxS5ts8a6u4gI=
=p9bU
-----END PGP SIGNATURE-----


More information about the vit-discuss mailing list