Problem 156 Luhn Algorithm checker error

Back to General discussions forum

johnnycake     2017-12-14 01:57:34

One of the numbers given was 6092612225147626. I left it alone since the checksum is 60. The expected answer transposed the 2nd and 3rd digits: 690261... This is an unnecessary swap since 09 and 90 give the same result.

WakeMeAtThree     2017-12-14 03:18:27
User avatar

Actually, all the input given in the Luhn Algorithm problem have to be fixed since the numbers are missing a number or have a mistakenly swapped pair of digits.

From the problem statement: "So please help Brother Kyprian to fix a list of bank card numbers. Some of them just miss one of digits and you should restore this digit. Others have a pair of adjacent digits swapped - you are to find the leftmost pair which, if swapped, makes valid card number."

^The keyword here is the 'Leftmost' swap criteria.

In the case of 6092612225147626, since it has no question mark, we assume it needs a swapfix that also passes the Luhn check, even though it already passes the Luhn check. The leftmost pair swap would look like:

#assume input has a swap error
6092612225147626 => 6902612225147626 

If the input was actually the swapped number 6902612225147626, then the answer would be:

#assume input has a swap error
6902612225147626 => 6092612225147626

Good luck! Much respect to you for using BASIC, my first brush with programming was with BASIC when I was in the 7th grade, and I loved it at the time.

Quandray     2017-12-14 07:08:43
User avatar

In one of the topics on here, I said "I'm probably the oldest on here". I'm 63 and it may have been true when I said it, but not anymore. Welcome Johnny.

johnnycake     2017-12-14 16:29:51

Thanks to you both for the encouragement. I've had some fun over the years playing around with BASIC although I did have a little formal training back in the 60's.
The language was ALGOL and we would write programs by punching stacks of IBM cards.

Regarding the problem, I did fail to notice that all the numbers had to be wrong. It does seem a little devious to slip in a number that nevertheless passes the algorithm. A lesson learned.

johnnycake     2017-12-14 23:22:18

I finally solved this problem after much aggravation. A curious thing that I noticed is that of the 51 numbers given, 5 of them had valid checksums and none of these 5 had "09" or "90" in them. The only swaps that could be made were of identical digits. So if the numbers were invalid no correction could be made. The unchanged numbers were accepted as correct.

Number Chk Swap
8971304472601008 60 44 3880814434549591 80 88 8380047878089766 80 00 6753786311949523 70 11
4001630049465557 60 00

Please login and solve 5 problems to be able to post at forum