Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all

I need to generate a series of digits with the following conditions.

say I start like this:

1 1 1 1 1 1 ==> ok
1 1 1 1 1 2 ==> ok
1 1 1 1 1 3 ==> not ok because if I replace 3 by 2 I get an existed series (1 1 1 1 1 2)
1 1 1 1 2 1 ==> ok
1 1 1 1 2 2 ==> ok
1 1 1 1 2 3 ok ==>
1 1 1 1 2 4 ==> not ok because if I replace 4 by 3 I get an existed series (1 1 1 1 2 3)
.....
1 1 2 3 1 1 ok ==>
1 1 3 2 1 1 ==> not ok because if I replace 2 by 3 and 3 by 2 I get an existed series (1 1 2 3 1 1)
2 2 3 4 2 2 ==> not ok because if I replace 2 by 1 I get an existed series (1 1 3 4 1 1 witch is like 1 1 2 3 1 1)

this is an example

1111
1112
1121
1122
1211
1212
1221
1222
1223
1231
1232
1233
1312

1

What I have tried:

I have no idea how to srart
this is a hard problem

thank you
Posted
Updated 9-Sep-20 1:07am
Comments
Patrice T 9-Sep-20 8:16am    
Give exact rules for the series.

1 solution

Quote:
this is a hard problem

Not really, when you think about it.

Start by doing it manually, on a piece of paper and make a note of what you do at each step.
Then do it again, following only the notes you made last time. If they don't work, change them and try again.
When you have the notes correctly generating your sequence successfully, you can start translating that into code, and it should be pretty trivial.

But I'd start by re-reading your assignment to check exactly what the rules are for "this sequence is not allowed" because your current ones are too vague:
1 1 1 1 1 1 ==> ok
1 1 1 1 1 2 ==> ok
1 1 1 1 1 3 ==> not ok because if I replace 3 by 2 I get an existed series (1 1 1 1 1 2)
Why is 1 1 1 1 1 2 allowed, when if I replace 2 by 1 I get an existing series?
 
Share this answer
 
Comments
Member 13569650 9-Sep-20 7:18am    
the replacement is with a digit that not 1 or 2 (not a digit in the series)
you use existing series digits if only you exchange the digits.

I tried what you say
but my difficulty is when the series is big I can not store all
the series and later check them with the current series because
its a very big number of series to manipulate

thank you
OriginalGriff 9-Sep-20 7:21am    
So now you have your rules sorted - possibly - get out the paper and pencil!
Patrice T 9-Sep-20 8:50am    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Member 13569650 9-Sep-20 10:11am    
to improve the question I say:

1111
1112
1113 bad because if I replace 3 by digit 2 ( 2 is not a part of this series)
1121
1122
1123
1211
1212
1213
1221
1222
1223
1231
1232
1233
1311 bad replace 3 by 2 get an existing series

also if I exchange between digits
like this.

from this 1221. to this. 2112
this also CAN gives an existing series.(note that 1122 and 2211 is not bad)


The series have 2 parameters
1 participate digits.
2 series length.

I hope this more clear.

thanks

I also get

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