Java 8、285 277バイト
import java.util.*;Set r=new HashSet();n->p("",((1<<3*n)+"").replaceAll(".","PRS"),n)void p(String p,String s,int n){int l=s.length(),i=0;if(l<1&&(s=p.substring(0,n)).equals(s.replaceAll("(.*)\\1","")))r.add(s);for(;i<l;p(p+s.charAt(i),s.substring(0,i)+s.substring(++i,l),n));}
Javaはほとんど常に冗長ですが、この場合は間違いなく、このような課題に適した言語ではありません。部分文字列を使用して順列を生成すると、パフォーマンスが低下し、効率が低下します。
しかし、間違いなくもう少しゴルフができます。
@Jakobのおかげで-8バイト。
説明:
ここで試してみてください。(パフォーマンスは3を超えるテストケースには悪すぎますが、ローカルでは機能します。)
import java.util.*; // Required import for Set and HashSet
Set r=new HashSet(); // Result-Set on class-level
n-> // Method with integer parameter and no return-type
p("",((1<<3*n)+"").replaceAll(".","PRS"),n)
// Get all permutations and save them in the Set
// End of method (implicit / single-line return-statement)
void p(String p,String s,int n){
// Separated method with 2 String & int parameters and no return-type
int l=s.length(), // The length of the second input-String
i=0; // Index-integer, starting at 0
if(l<1 // If the length is 0,
&&(s=p.substring(0,n)).equals(s.replaceAll("(.*)\\1","")))
// and it doesn't contain a repeated part:
r.add(s); // Add it to the result-Set
for(;i<l; // Loop (2) from 0 to `l`
p( // Recursive-call with:
p+s.charAt(i), // Prefix-input + the character of the second input at index `i`
s.substring(0,i)+s.substring(++i,l),
// and the second input except for this character
n) // and `n`
); // End of loop (2)
} // End of separated method
n>3
繰り返される文字と繰り返されるシーケンスについて混乱が生じているため、テストケースを作成することをお勧めします。