From: Paul Novak Date: 2007-05-04T04:35:04+09:00 Subject: Re: Checking Credit Cards (#122) One more way to do it: mutually recursive functions that each strip off the last character and alternate the doubling: http://pastie.caboo.se/58669 or def luhn_sum s val = s.slice!(-1) if val==nil return 0 end val.chr.to_i + luhn_helper( s) end def luhn_helper s val = s.slice!(-1) if val==nil return 0 end (2 * val.chr.to_i).to_s.split("").inject(0){|sum,x|sum + x.to_i} + luhn_sum( s) end def luhn? s luhn_sum(s) % 10 == 0 end Regards, Paul.