From: Ari Brown on 28 Apr 2007 23:04 On Apr 27, 2007, at 7:59 AM, Ruby Quiz wrote: <snippage> > > 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. Uh, this is probably just affecting me but.... In his example, after he doubles the second to last digit (call it d), he uses mod10 on it (9*2 = 18 %10 = 8). That is the way to get his numbers, but a) where does he say that and b) where do the 10 and 14 come from? Help me, hyperactive ruby posters! ~ Ari English is like a pseudo-random number generator - there are a bajillion rules to it, but nobody cares.
From: Philip Gatt on 28 Apr 2007 23:30 You move back to the beginning after doubling the 2nd to last. You double every other one on the way back to the beginning. The 10 is 5*2 and the 14 is 7*2 On Apr 28, 2007, at 8:04 PM, Ari Brown wrote: > > On Apr 27, 2007, at 7:59 AM, Ruby Quiz wrote: > <snippage> >> >> 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. > > Uh, this is probably just affecting me but.... > > In his example, after he doubles the second to last digit (call it > d), he uses mod10 on it (9*2 = 18 %10 = 8). That is the way to get > his numbers, but a) where does he say that and b) where do the 10 > and 14 come from? > > Help me, hyperactive ruby posters! > ~ Ari > English is like a pseudo-random number generator - there are a > bajillion rules to it, but nobody cares. > >
From: Phrogz on 28 Apr 2007 23:45 On Apr 28, 9:04 pm, Ari Brown <a...(a)aribrown.com> wrote: > On Apr 27, 2007, at 7:59 AM, Ruby Quiz wrote: > > 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. > > Uh, this is probably just affecting me but.... > > In his example, after he doubles the second to last digit (call it > d), he uses mod10 on it (9*2 = 18 %10 = 8). That is the way to get > his numbers, but a) where does he say that and b) where do the 10 and > 14 come from? The confusing part (that I didn't catch when I read it) is that step 2 is to sum all the *digits*, not the numbers. So step 1) 9 * 2 = 18 step 2) 1 + 8 He's not modding the result of the multiplication by 10, but rather adding up the resulting component digits. The same occurs with the 10 and 14 (which Philip pointed out are the result of 5*2 and 7*2, respectively).
From: Harry on 28 Apr 2007 23:47 On 4/27/07, Ruby Quiz <james(a)grayproductions.net> wrote: > > 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. > > This Ruby Quiz has been translated into Japanese. Maybe there will be more people participating. http://d.hatena.ne.jp/nappa_zzz/20070429 Harry -- http://www.kakueki.com/ruby/list.html A Look into Japanese Ruby List in English
From: James Edward Gray II on 29 Apr 2007 00:22
On Apr 28, 2007, at 10:50 PM, Phrogz wrote: > On Apr 28, 9:04 pm, Ari Brown <a...(a)aribrown.com> wrote: >> On Apr 27, 2007, at 7:59 AM, Ruby Quiz wrote: >>> 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. >> >> Uh, this is probably just affecting me but.... >> >> In his example, after he doubles the second to last digit (call it >> d), he uses mod10 on it (9*2 = 18 %10 = 8). That is the way to get >> his numbers, but a) where does he say that and b) where do the 10 and >> 14 come from? > > The confusing part (that I didn't catch when I read it) is that step 2 > is to sum all the *digits*, not the numbers. > > So > step 1) 9 * 2 = 18 > step 2) 1 + 8 > > He's not modding the result of the multiplication by 10, but rather > adding up the resulting component digits. The same occurs with the 10 > and 14 (which Philip pointed out are the result of 5*2 and 7*2, > respectively). Yes, most descriptions tell you to mod 10 the bigger numbers to get the back to a single digit, but that adds a step that doesn't have any affect. I left it out. James Edward Gray II |