Luhn Algorithm Problem 156 (possible bug)

Back to General discussions forum

Radovan Markus     2019-04-23 11:52:13
User avatar

Hello! I was solving the problem #156. When I posted solution it was inccorect so I investigated what's wrong becuase my answer was identical with the answer of the server. It took me a while to figure out that the problem was swapping.

So first of all I want to ask if there are any rules about credits cards which I am missing. If no, then this may be a bug (or also problem on my side with program).

I did some check with calculator and program rewrite before posting here. Before posting solutions I always try example input to see if my program is working correctly (works most of times). So I also did it with this problem and it seems that my answer was not identical with the example solution but the checksum for both, my output and example was correct (and proboably by coincidence, the same). I made output for calculations of checksum so I could copy it to google calculator to make sure it's really correct and it was!

Here is the picture . It may seem a bit messy, my number is highlighted with purple color and example with orange color. Difference is in:

(my) 1217400151419495 and (example) 1217400151414995

My checkSum: ( 1217400151419495 ) 5 + (9 * 2 - 9 ) + 9 + (4 * 2) + 1 + (4 * 2) + 1 + (5 * 2 - 9 ) + 1 + (0 * 2) + 4 + (0 * 2) + 7 + ( 1 * 2 ) + 2 + (1 * 2) = 60

Codeabbey's checksum: ( 1217040151414995 ) 5 + (9 * 2 - 9 ) + 4 + (9 * 2 - 9) + 1 + (4 * 2) +1 + (5 * 2 - 9) + 1 + (0 * 2) + 0 + (4 * 2) + 7 + (1 * 2) + 2 + (1 * 2 ) = 60

My answer: (1217400151419495) Right answer: (1217040151414995) Input: (1217400151414995) I swapped different two numbers here.

If it was a bug I think that someone else would notice before me, but afterall the checksum is right. I tried to post answer several times to make sure that I have right input and so and my answer was always wrong but the given data were almost identical.

I don't really know how is this task checked, if my input is compared to one with generated (and if so this might be the problem) or it checks the checksum for my input (in this case problem would be on my side).

Rodion (admin)     2019-04-23 19:52:44
User avatar

Radovan, Hi again - glad to hear from you! :)

Really, the case with swapped digits is awkward, as in randomly generated number we can have more than one such pair. Problem statement says:

...you are to find the leftmost pair which, if swapped, makes valid card number...

However it seems this line is not written too bold and could be missed. Probably it would be better to improve checker so that it either won't generate numbers with more than one swaps possible, or to make it clever enough to accept any suitable answer. I'm sorry for this and hope to look into this in the nearest future...

Radovan Markus     2019-04-24 15:40:09
User avatar

Rodion hi!

I didn't notice this part. Sorry about it! But checksum was right so my post wasn't that much useless as I expected.

Well anyways thanks for your reply! ^ _ ^

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