------art_93495_31148974.1177871985963
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

This is my first quiz submission.  The only testing I did was running the
cards I had in my wallet.  It seems to work.  I'm sure there's a much better
way to implement this, but here it is:

#card_check.rb

def check_type(number)
  #Returns a string representing the type of card if the length and
leading
  #  digits are valid.  Otherwise returns "Unknown".
  valid  
    /^(34|37)/ [15,"AMEX"],
    /^6011/ [16,"Discover"],
    /^(51|52|53|54|55)/ [16,"MasterCard"],
    /^4/ [13,16,"Visa"]
  }
  number.gsub!(/ /,"")
  valid.each_key do |i|
    if number i
      return valid[i][-1] if valid[i].include? number.length
    end
  end
  return "Unknown"
end

def luhn(number)
  # Returns "valid" if the number passes the Luhn algorihm criteria.
Returns
  #   "invalid" if the algorithm fails.
  number  umber.gsub(/ /,"").split(//).reverse
  new_number  "
  number.each_index do |i|
    new_number << (number[i].to_i*2).to_s if (i+1) % 2 0
    new_number << number[i] if (i+1) % 2 1
  end
  new_number  ew_number.split(//)
  sum  
  new_number.each_index { |i| sum + ew_number[i].to_i }
  return "valid" if sum % 10 0 unless number.length 0
  return "invalid"
end

def validate_card(number)
  puts "Type:   #{check_type(number)}"
  puts "Status: #{luhn(number)}"
end

validate_card(ARGV.join("")) if __FILE__ $0

------art_93495_31148974.1177871985963--