Algorithm Challenge

G

Guest

I am trying to create a check digit worksheet for an algorithm where staff
have to use the algorithm hundreds of times daily, so it has to be quick and
efficient.

The algorithm works where the first 12 digits are multiplied and summed
using simple math, and the REMAINDER of the of the sum divided by 9 must
equal the 13th digit.

For example:
My number is 0500450002883, so
1x0=0
2x5=10
3x0=0
4x0=0
5x4=20
6x5=30
7x0=0
8x0=0
9x0=0
10x2=20
11x8=88
12x8=96
where the sum = 264. If you divide 264 by 9, the remaider is 3, the check
digit.

What formula can I use to produce the remaider for 264/9 instead of getting
29.33?
 
B

Bob Phillips

=MOD(SUMPRODUCT(--(MID(A17,ROW(INDIRECT("1:12")),1)),ROW(INDIRECT("1:12"))),
9)
 
B

Bernard Liengme

To add to Bob's reply:
The value must be entered as '0500450002883 to preserve the leading zero
To check if remainder equals 13th digit:
=MOD(SUMPRODUCT(--(MID(A17,ROW(INDIRECT("1:12")),1)),ROW(INDIRECT("1:12"))),
9)=VALUE(RIGHT(A17))
The INDIRECT is not needed unless you plan to copy the formula to other
cells
=MOD(SUMPRODUCT(--(MID(A19,ROW(1:12),1)),ROW(1:12)),
9)=VALUE(RIGHT(A19)
best wishes
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email
 
B

Bob Phillips

The value must be entered as '0500450002883 to preserve the leading zero

You could always force it

=MOD(SUMPRODUCT(--(MID(TEXT(A1,"0000000000000"),ROW(INDIRECT("1:12")),1)),RO
W(INDIRECT("1:12"))),9)
 
H

Harlan Grove

Bob Phillips wrote...
....
You could always force it

=MOD(SUMPRODUCT(--(MID(TEXT(A1,"0000000000000"),ROW(INDIRECT("1:12")),1)),
ROW(INDIRECT("1:12"))),9)

Why not just treat it as a number in the first place?

=MOD(SUMPRODUCT(INT(A1/10^{1;2;3;4;5;6;7;8;9;10;11;12})
-10*INT(A1/10^{2;3;4;5;6;7;8;9;10;11;12;13}),
{12;11;10;9;8;7;6;5;4;3;2;1}),9)

This is lots longer, but if you name the array something like ARRAY, it
becomes

=MOD(SUMPRODUCT(INT(A1/10^ARRAY)-10*INT(A1/10^(1+ARRAY)),13-ARRAY),9)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top