Luhns algorithm bizarre behaviour

Back to General discussions forum

shady_slim     2024-11-30 06:21:08

My solution passed. But then I ran it the second time, it didn't pass. In around 10 attempts since first AC verdict, only once I received an AC verdict, failed rest of the times. The changes I made were just addding a space after string modifier in

printf(" %s ", buffer);

when accepting input string/number. I added the space in front before. diffing my solution and correct solution provided doesn't really help, I see same numbers but somehow its not accepted.

shady_slim     2024-12-02 07:51:53

Colleagues with higher rank, click this for me, please!

TestUser     2024-12-08 10:56:49
User avatar

Hi Friend! Sorry for delay, but seemingly there is not much activity here in these days and people probably are somewhat busy elsewhere.

The changes I made were just addding a space after string modifier in

avoid doing random changes in hope that something may magically fix your code :) better try to find out the issue

moreover that second space should not work (checker will strip spaces before and after the answer but won't reduce extra spaces inside).

diffing my solution and correct solution provided doesn't really help, I see same numbers

You probably do not check them carefully enough (you can do this programmatically rather than by eye, right?)

For example, I tried to run your solution and see discrepancy in the first line of the answer

expected:
7482630860903216 9496604566651023 2350629830501795 5645664644221528 6795677065218423
5750060375722175 3977791541545023 9918549670720828 ...

your answer:
7482630860903216 9496604566651023 2350629830501795 5645664644221528 6795677065218423
5750060375722175 3977791541545023 8918549670720828 ...

input was like this:
47
74826308?0903216
9946604566651023
2350692830501795
5645666444221528
6795677065218?23
575006037572?175
3977791451545023
?918549670720828
...

Check this example and most probably you will see that sometimes your code works slightly incorrectly. Fix it and all should be fine.

P.S. as a sidenote I'd recommend not add comments like STARTING POINT: MAIN before the main and FUNCTIONS: Alphabetical or Prototypes. You give your functions less or more meaningful names - and it is considered the best way to create "self-documented" code. Extra comments may look useless and even confusing - for example, as main is not in alphabetical order or comment Flags before three variables one of which is called buffer and seems to be not a flag at all :)

This is not criticism, be sure - feel free to write the code in any way comfortable for you - just a kind of friendly advice considering current industrial practices. You may have seen this joke about comment for stop sign.

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