From: Christian Neukirchen Date: 2007-05-04T22:31:26+09:00 Subject: Re: [QUIZ] Checking Credit Cards (#122) Daniel Martin writes: > Just one minor nit: > > Christian Neukirchen 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? So that makes this method: I first thought that too, and it cost me 10min to find that 9%9 == 0. -- Christian Neukirchen http://chneukirchen.org