Skip to content

Instantly share code, notes, and snippets.

@vvalgis
Last active September 24, 2015 18:18
Show Gist options
  • Save vvalgis/789593 to your computer and use it in GitHub Desktop.
Save vvalgis/789593 to your computer and use it in GitHub Desktop.
Credit card number validation
def ccn_valid?(number)
(number.to_s.split(//).inject([]){ |r,d| r << (r.count.even? ? (d.to_i * 2).to_s : d); r }.map{|d| d.split(//)}.flatten.inject(0){|sum,d| sum += d.to_i} % 10) == 0
end
puts ccn_valid?("4417123456789113")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment