Xian Lu
Xian Lu

Reputation: 1

algorithm for permutations of a list with specific orders for certain variables

I wanted to ask if there was a way to use an algorithm or some program to actually get a list back with all the permutations of a sequence of specific variables, but there can only be certain variables in certain places. I'm trying to find a way to create uniquely designed name for something, and for examples' sake, let's use the name "Coda." That would be the way to pronounce it, but I want to use a name like "{ 0 |] 4." Obviously I wouldn't want the "C" to wind up anywhere else. But there are other options than "{" for the "C." For instance, "[ 0 |] 4." And in place of the "0" for "o," I could use "()," as in "{ () |] 4." But I could also use that same "()" in the second example for "C," and it would be "[ () |] 4." But I wouldn't want the things I use for "o" to be anywhere else in the name, like instead of "4," it and the "()" are switched, spelling out "Cado." Not exactly the word I'm looking for. But I'm wondering if there's a way to list out entirely all permutations, with certain things always having to be in a certain place.

These would be like what I would use for all possibilities of the letters, which is why it got so complicated when I started trying to list out all the permutations myself (obviously the commas aren't part of the letters):

C: <, [, {, (

o: 0, (), [], {}

d: |>, |], |},|)

a: 4, /\, /-\, /=\, @

Upvotes: 0

Views: 51

Answers (1)

Leo
Leo

Reputation: 142

First of all, I should note that permutation is not the correct term: 'coda'->'daoc' is a permutation, and is not what you want to do.

If you want to print 'Coda' with all possible combination of variations for each character, you just need to have four nested cycles, one for each character.

In pseudocode, you would have:

c_chars = ['<', '[', '{', '(']
o_chars = ['0', '()', '[]', '{}']
d_chars = ['|>', '|]', '|}','|)']
a_chars = ['4', '/\', '/-\', '/=\', '@']

foreach c in c_chars{
  foreach o in o_chars{
    foreach d in d_chars{
      foreach a in a_chars{
        print(c+o+d+a+'\n') //concatenate the four characters
      }
    }
  }
}

This would print 4*4*4*5=320 lines, each with a different way of spelling 'Coda' with your indicated possibilities.

Upvotes: 1

Related Questions