Computer programming challenge in the language of your choice

Captain Caveman

Platinum Member
Jun 14, 2020
13,277
7,411
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
 
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

Man I really wanted to delve into this so I appreciate the challenge question it often motivates me when such questions come up so I hope you post them again in the future (on any subject, not just programming) as my brain thirsts for activity and problem solving.

On that note, I'm too tired though today. I just answer this thread to bring activity to the post in passive support and to encourage others to tackle it. I hope to see some responses.
 
Man I really wanted to delve into this so I appreciate the challenge question it often motivates me when such questions come up so I hope you post them again in the future (on any subject, not just programming) as my brain thirsts for activity and problem solving.

On that note, I'm too tired though today. I just answer this thread to bring activity to the post in passive support and to encourage others to tackle it. I hope to see some responses.
In a past job, the employer had hand held scanners for stock takes. I looked into the programs on the unit and noticed it uses 21212 and the checksum to validate codes. Before scanners really appeared as an everyday device in the workplace, 6 digits codes had to be inputted, so to reduce error, this checksum system was used. Even then, if the valid code wasn't being used against an item, the transaction was thrown over to a dump code on the overnight update run. I think it was 000018, but this was some 30 years ago, lol

A colleague did the program on a hand held Psion unit, I did mine on the Sinclair QL and won. Just because you don't have to convert between numbers and strings on the QL.
 
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
In pseudocode:

Input = 303024

C1 = substr(Input, 1, 1)
C2 = substr(Input, 2, 1)
C3 = substr(Input, 3, 1)
C4 = substr(Input, 4, 1)
C5 = substr(Input, 5, 1)

Sum = (
(Cast(C1 as int) * 2) +
(Cast(C2 as int) * 1) +
(Cast(C3 as int) * 2) +
(Cast(C4 as int) * 1) +
(Cast(C5 as int) * 2)
)

CheckSum = (Round(Sum / 10) * 10) - Sum

?!? Now what tells you if the string is valid?
 
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
there are many computer programming challenges you can try to improve your skills. Some popular online platforms that offer coding challenges include LeetCode, HackerRank, CodeSignal, and CodeWars.

These platforms provide a variety of problems ranging from beginner to advanced levels in different programming languages.

Here are a few types of programming challenges you can try:

1. Algorithmic challenges: These challenges focus on solving problems efficiently using algorithms and data structures.

2. Coding puzzles: These challenges test your problem-solving skills and ability to write clean and concise code.

3. Competitive programming challenges: These challenges are timed and test your ability to quickly solve problems under pressure.

4. Project-based challenges: These challenges involve building complete projects or applications to showcase your programming skills.

By participating in these challenges regularly, you can enhance your problem-solving abilities, improve your coding skills, and stay up-to-date with the latest trends in the field of computer programming.

It's a great way to learn new concepts, practice coding techniques, and challenge yourself to become a better programmer.

Algorithmic challenge==> how to win the the US presidential election? Any effective algorithms for that? Just assassinate Trump or Harris? lol. Fooling around! :)
 
there are many computer programming challenges you can try to improve your skills. Some popular online platforms that offer coding challenges include LeetCode, HackerRank, CodeSignal, and CodeWars.

These platforms provide a variety of problems ranging from beginner to advanced levels in different programming languages.

Here are a few types of programming challenges you can try:

1. Algorithmic challenges: These challenges focus on solving problems efficiently using algorithms and data structures.

2. Coding puzzles: These challenges test your problem-solving skills and ability to write clean and concise code.

3. Competitive programming challenges: These challenges are timed and test your ability to quickly solve problems under pressure.

4. Project-based challenges: These challenges involve building complete projects or applications to showcase your programming skills.

By participating in these challenges regularly, you can enhance your problem-solving abilities, improve your coding skills, and stay up-to-date with the latest trends in the field of computer programming.

It's a great way to learn new concepts, practice coding techniques, and challenge yourself to become a better programmer.

Algorithmic challenge==> how to win the the US presidential election? Any effective algorithms for that? Just assassinate Trump or Harris? lol. Fooling around! :)
My programming background was the Sinclair Spectrum, then the Sinclair QL. On the QL, I was self learning machine code and I used to write scripts for Archive (database program on the QL). Dabbled with hand held Psions and then self learning Delphi when had my first Pentium PC. Then nothing for 30 years.

So I imagine many languages have come and gone over the decades.
 

Forum List

Back
Top