Click here to Skip to main content
15,399,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to create a code that consists of 4 parts, each part consists of five letters or numbers ,for example :a9898-1G343-m1Y3R-77Eqc
I want this serial code to occur according to certain rules:
Rule 1: even number of digits counting the first character in each segment (a, 1, m, 7  2/4 are digits, 2 is an even number). [a9898-1G343-m1Y3R -77Eqc]
Rule 2: every segment has at least1 alphabet.[ a9898-1G343-m1Y3R -77Eqc]
Rule 3: sum of digits is (9+8+9+8+1+3+4+3+1+3+7+7) = 63 which is more than 40. [a9898-1G343-m1Y3R -77Eqc]
Rule 4: 7+7 = 14 which is less than 15. [a9898-1G343-m1Y3R -77Eqc]
Rule 5: 3rd, 12th character are digits and add up to 9 (8+1). [a9898-1G343-m1Y3R -77Eqc]
Rule 6: at least 3 caps and 2 lower case. [a9898-1G343-m1Y3R -77Eqc]
Rule 7: distance of 4 or more steps in the alphabet between consecutive characters: (a,g)=6, (g,m)= 6, (m,y) = 12, and so on, all of them being at least 4 characters away. [a9898-1G343-m1Y3R -77Eqc]

What I have tried:

I tried several methods but could not identify the 4 parts and then separate letters by letter and apply the rules Can someone enlighten my mind and explain me how to do this. It's the second week and I can't solve the code, thanks a lot
Updated 21-Dec-21 9:56am
Richard MacCutchan 21-Dec-21 8:44am
It is just a question of applying each rule to the segments you create. You could start by selecting a set of alphabetic characters which fit all the rules. You can then pick the characters in sequence as you create each segment. Similarly you could create a set of digits that fit the rules pertaining to digits. Then as you create each segment, again you need to select the appropriate number of digits.

1 solution

Rule 4 is incomplete.

I would generate the code by applying the rules in order of most restrictive (probably Rule 5) to least restrictive (probably Rule 6). So, starting with Rule 5, generate two digits and assign them to the beginning of two substrings. Then generate two alphabetic characters and assign them to the beginning of the other two substrings. Generate means select at random.

As you fill in more of the empty slots in the string, verify that what you have so far still satisfies all of the rules. If it doesn't, discard the characters that you generated in the last step and generate new ones. Eventually you'll end up with a string that satisfies all of the rules.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900