On May 2, 2007, at 3:18 PM, Daniel Martin wrote:

> Just one minor nit:
>
> Christian Neukirchen <chneukirchen / gmail.com> writes:
>
>> def luhn?(n)
>>   f = 2
>>   (n.delete("^0-9").reverse.split(//).map{|d|d.to_i}.
>>      inject(0) { |a,e| f=3-f; a + (e*f > 9 ? e*f-9 : e*f) } %  
>> 10).zero?
>> end
>
> You do know that (e*f > 9 ? e*f-9 : e*f) is equivalent to e*f%9,
> right?

 >> (0..9).map { |n| n * 2 % 9 }
=> [0, 2, 4, 6, 8, 1, 3, 5, 7, 0]
 >> (0..9).map { |n| n * 2 > 9 ? n * 2 - 9 : n * 2 }
=> [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]

James Edward Gray II