Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Incubator Q&A

Welcome to the staging ground for new communities! Each proposal has a description in the "Descriptions" category and a body of questions and answers in "Incubator Q&A". You can ask questions (and get answers, we hope!) right away, and start new proposals.

Are you here to participate in a specific proposal? Click on the proposal tag (with the dark outline) to see only posts about that proposal and not all of the others that are in progress. Tags are at the bottom of each post.

Find the shortest possible string containing all permutations of 1, 2, 3 Question

+2
−0

There are 6 permutations of the numbers 1, 2, 3.

They are:

123
132
213
231
312
321

The goal is to make a string (as short as possible) using the digits 1, 2 and 3 so that each of the above 6 permutations occur at least once in consecutive positions in the string.

The sample string below contains all 6 permutations. The string is 12 digits long but there are shorter strings that contain all 6 permutations.

As examples, the permutation 213 occurs in the positions marked AAA and the permutation 123 occurs in the positions marked BBB.

  AAA    BBB
132132323123

What is the shortest string that satisfies the above conditions?


I know what the shortest string length is.

If you post a correct string with that shortest possible length, I plan to upvote your answer.

If you also give a proof that your answer is minimal which I find easy to understand, I plan to mark your answer as Works for me.

History

0 comment threads

1 answer

+3
−0
Proposed solution123121321 for 9 symbols.
Reasoning

The first three symbols should be a permutation because otherwise we can trim the first symbol without losing any permutation. Without loss of generality we can start with 123. Given a prefix, call a one-symbol continuation of it "good" if it contributes a new permutation.

The only good continuation of 123 is 1, and the only good continuation of 1231 is 2. There are no good continuations of 12312 because 123 is already contained in the string. So we have three permutations in five symbols. The other three permutations can similarly be done in five symbols, and by choosing to start at 2 we can overlap and save a symbol, giving nine symbols in total.

The result has only one three-symbol substring which doesn't contribute a necessary permutation: the central 121. To improve on that would require starting with a permutation and making five good extensions, and we've already seen that this is impossible.

History

0 comment threads

Sign up to answer this question »