Python Forum
Algorithm to generate a combination
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algorithm to generate a combination
#1
How to generate a combination of a password:

The vault password is a combination of 3 letters followed by 3 digits in the LLLDDD format. In addition, it has the following clues:
1 - The password corresponds to a number in hexadecimal. (This means that only the letters A, B, C, D, E and F are valid.)
2 - There are no repeated letters.
3 - The letters A and D are present in the password.
4 - The first digit is 3 or 6
5 - The sum of the digits is 8.
6 - The digit zero does not appear in the password

How to develop a code that lists all possible combinations? Huh

Thanks ;)
Reply
#2
what have you tried?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Aug-15-2020, 05:03 PM)buran Wrote: what have you tried?

I tried use itertools

like this:
import itertools
for comb in itertools.combinations(['A', 'B', 'C', 'D', 'E', 'F', 1, 2, 3, 4, 5, 6, 7, 8, 9], 6):
print (comb)

but I fail to treat the rules
Reply
#4
Maybe you should solve the problem before you start writing the program?

Some very basic analysis makes the problem easier.

These are all related:
The first digit is either 3 or 6.
Zero does not appear in the password.
The sum of all digits is 8.

If the first digit is 6, what are the possibilities for the other two digits?
If the first digit is 3, what are the possibilities for the other two digits?
How many digit combinations are there? Knowing this number does it make more sense to hardcode the digit combinations or write code to create the combinations?

These are related:
Only the letters A, B, C, D, E and F are valid.
There are no repeated letters.
The letters A and D are present in the password.

I would start by writing each possible combination of letters. How many are there? What were the steps you used to make the list of combinations? Is your logic easily translated to Python?
Reply
#5
(Aug-15-2020, 09:07 PM)deanhystad Wrote: Maybe you should solve the problem before you start writing the program?

Some very basic analysis makes the problem easier.

These are all related:
The first digit is either 3 or 6.
Zero does not appear in the password.
The sum of all digits is 8.

If the first digit is 6, what are the possibilities for the other two digits?
If the first digit is 3, what are the possibilities for the other two digits?
How many digit combinations are there? Knowing this number does it make more sense to hardcode the digit combinations or write code to create the combinations?

These are related:
Only the letters A, B, C, D, E and F are valid.
There are no repeated letters.
The letters A and D are present in the password.

I would start by writing each possible combination of letters. How many are there? What were the steps you used to make the list of combinations? Is your logic easily translated to Python?

Yes, I solved the whole combination. There are 120 possibilities.

The digits can only be:
6 1 1
3 1 4
3 2 3
3 3 2
3 4 1

And the letters:
A D B
A D C
A D E
A D F

A B D
A C D
A E D
A F D

B A D
C A D
E A D
F A D

D A B
D A C
D A E
D A F

D B A
D C A
D E A
D F A

B D A
C D A
E D A
F D A

There are 24 letter combinations X 5 number combinations = 120

My problem is build the algorithm to generate these combinations.
Reply
#6
Since there is only one valid combination that starts with 6 maybe you generate the permutations that start with 3 and add 611. Now you know that the second and third digit can only be 1, 2, 3 or 4.

Do you have an idea on how to attack the letters?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop to find the best combination/score KoinKoin 21 27,015 Jan-05-2023, 10:31 AM
Last Post: KoinKoin
  loops in combination with lists Juru 4 2,821 May-07-2020, 02:58 PM
Last Post: Marbelous

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020