From: John Joyce on 27 Apr 2007 08:10 On Apr 27, 2007, at 8:59 PM, Ruby Quiz wrote: > The three rules of Ruby Quiz: > > 1. Please do not post any solutions or spoiler discussion for this > quiz until > 48 hours have passed from the time on this message. > > 2. Support Ruby Quiz by submitting ideas as often as you can: > > http://www.rubyquiz.com/ > > 3. Enjoy! > > Suggestion: A [QUIZ] in the subject of emails about the problem > helps everyone > on Ruby Talk follow the discussion. Please reply to the original > quiz message, > if you can. > > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- > =-=-=-=-=-=-= > > Before a credit card is submitted to a financial institution, it > generally makes > sense to run some simple reality checks on the number. The numbers > are a good > length and it's common to make minor transcription errors when the > card is not > scanned directly. > > The first check people often do is to validate that the card > matches a known > pattern from one of the accepted card providers. Some of these > patterns are: > > +============+=============+===============+ > | Card Type | Begins With | Number Length | > +============+=============+===============+ > | AMEX | 34 or 37 | 15 | > +------------+-------------+---------------+ > | Discover | 6011 | 16 | > +------------+-------------+---------------+ > | MasterCard | 51-55 | 16 | > +------------+-------------+---------------+ > | Visa | 4 | 13 or 16 | > +------------+-------------+---------------+ > > All of these card types also generate numbers such that they can be > validated by > the Luhn algorithm, so that's the second check systems usually > try. The steps > are: > > 1. Starting with the next to last digit and continuing with every > other > digit going back to the beginning of the card, double the digit > 2. Sum all doubled and untouched digits in the number > 3. If that total is a multiple of 10, the number is valid > > For example, given the card number 4408 0412 3456 7893: > > Step 1: 8 4 0 8 0 4 2 2 6 4 10 6 14 8 18 3 > Step 2: 8+4+0+8+0+4+2+2+6+4+1+0+6+1+4+8+1+8+3 = 70 > Step 3: 70 % 10 == 0 > > Thus that card is valid. > > Let's try one more, 4417 1234 5678 9112: > > Step 1: 8 4 2 7 2 2 6 4 10 6 14 8 18 1 2 2 > Step 2: 8+4+2+7+2+2+6+4+1+0+6+1+4+8+1+8+1+2+2 = 69 > Step 3: 69 % 10 != 0 > > That card is not valid. > > This week's Ruby Quiz is to write a program that accepts a credit > card number as > a command-line argument. The program should print the card's type > (or Unknown) > as well a Valid/Invalid indication of whether or not the card > passes the Luhn > algorithm. > For completeness and to make this Quiz exercise valid to more people, can anyone include the information for other major credit cards from major countries? Japan: JCB, et. al., U.K.: Barclay, et. al. , etc... This would be good to expand the exercise and return more to our friends in various areas! Discover is itself not found outside of North America, AFIK.
From: Tim Becker on 27 Apr 2007 08:22 > For completeness and to make this Quiz exercise valid to more people, > can anyone include the information for other major credit cards from > major countries? Japan: JCB, et. al., U.K.: Barclay, et. al. , etc... UK had Switch and Solo till recently which are now rebranded under the Maestro umbrella. They're not really credit cards and basically no rules exist, you have to check tables to determine valid prefixes and card number length. Additionally, Maestro card numbers may also be Mastercard numbers, so they can't be uniquely identified as being Maestro. For JCB and Diner's: JCB 3528-2589 Length: 16 Diners 3000-3029, 3040-3059, 36, 3815-3889, 389 Length: 14 Cheers, -Tim
From: Daniel Martin on 27 Apr 2007 08:36 Ruby Quiz <james(a)grayproductions.net> writes: > This week's Ruby Quiz is to write a program that accepts a credit > card number as a command-line argument. The program should print > the card's type (or Unknown) as well a Valid/Invalid indication of > whether or not the card passes the Luhn algorithm. May I make an additional suggestion? Treat spaces in the card number as perfectly valid, and simply strip them before processing. One of the most irritating features found in many online stores is the requirement that the credit card number be typed in with no spaces. (The other biggie is using a select box for the state abbreviation) Now granted, for accepting the card number from the command line this will mean that on the command line the card number was quoted, but presumably most people's programs will be a command-line wrapper around a function/class that does the real work. -- s=%q( Daniel Martin -- martin(a)snowplow.org puts "s=%q(#{s})",s.to_a[1] ) puts "s=%q(#{s})",s.to_a[1]
From: James Edward Gray II on 27 Apr 2007 08:54 On Apr 27, 2007, at 7:36 AM, Daniel Martin wrote: > Now granted, for accepting the card number from the command line this > will mean that on the command line the card number was quoted... It doesn't have to mean that: $ ruby -e 'p ARGV.join' 1111 2222 3333 4444 "1111222233334444" James Edward Gray II
From: John Joyce on 27 Apr 2007 09:10
On Apr 27, 2007, at 9:22 PM, Tim Becker wrote: >> For completeness and to make this Quiz exercise valid to more people, >> can anyone include the information for other major credit cards from >> major countries? Japan: JCB, et. al., U.K.: Barclay, et. al. , >> etc... > > UK had Switch and Solo till recently which are now rebranded under the > Maestro umbrella. They're not really credit cards and basically no > rules exist, you have to check tables to determine valid prefixes and > card number length. Additionally, Maestro card numbers may also be > Mastercard numbers, so they can't be uniquely identified as being > Maestro. > > For JCB and Diner's: > > JCB 3528-2589 Length: 16 > Diners 3000-3029, 3040-3059, 36, 3815-3889, 389 Length: 14 > > > Cheers, > -Tim > Wow, those are some broad ranges. |