The scenario. A 6 digit code is made up of 5 digits and a checksum digit. The checksum validates the first 5 numbers against a multiplication of 21212
So for example 303024. Do the 21212 multiplication on the first 5 numbers and add them together.
Take the first digit, multiply by 2.
Second digit multiplied by 1.
Third digit multiply it by 2, and so on.
You get 6+0+6+0+4 = 16
To get 16 upto the nearest whole tens number (so 20 in this example, you need to add 4). So the last digit is the checksum to valid that 6 digit code
If you take 785485 there's an extra step when a number is greater than 10 -
7x2 = 14 so 1+4 = 5
8x1 = 8
5x2 = 10 so 1+0 = 1
4x1 = 4
8x2 = 16 so 1+6 = 7
5+8+1+4+7 = 25 so move up to 30 takes 5. The checksum is 5.
So the challenge is, write the shortage computer program that wants a 6 digit number, it applies the 21212 against it, and then tells you if it's valid or not.
I did this on the Sinclair QL way back in the 90's on the QDOS operating system. I can dig it out if anyone is interested in this crap
So for example 303024. Do the 21212 multiplication on the first 5 numbers and add them together.
Take the first digit, multiply by 2.
Second digit multiplied by 1.
Third digit multiply it by 2, and so on.
You get 6+0+6+0+4 = 16
To get 16 upto the nearest whole tens number (so 20 in this example, you need to add 4). So the last digit is the checksum to valid that 6 digit code
If you take 785485 there's an extra step when a number is greater than 10 -
7x2 = 14 so 1+4 = 5
8x1 = 8
5x2 = 10 so 1+0 = 1
4x1 = 4
8x2 = 16 so 1+6 = 7
5+8+1+4+7 = 25 so move up to 30 takes 5. The checksum is 5.
So the challenge is, write the shortage computer program that wants a 6 digit number, it applies the 21212 against it, and then tells you if it's valid or not.
I did this on the Sinclair QL way back in the 90's on the QDOS operating system. I can dig it out if anyone is interested in this crap