public
Created

  • Download Gist
luhn.rb
Ruby
1
def luhn? n;s=0;n.size.times{|i|x=n[-(i+1),1].to_i*(i%2+1);s+=x>9?x+1:x};s%10==0;end
def luhn? n;s=0;n.size.times{|i|x=n[-i-1,1].to_i*(i%2+1);s+=x>9?x+1:x};s%10==0;end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.