Upon the rumor that Codegolf will have a Rock-Paper-Scissors tournament you look into the topic of square-free words. A word made of the letters
S is square-free if it does not contain a sequence that repeats twice. That is to say, the word can not be written as
a x x b
b are words of any length and
x is a word of length at least one, all made of the letters
Write a program that generates the square-free words of the letters
S of length
n where the number
1 <= n <= 10 is taken as input.
For example the square-free words of length 3 are
and those of length 4 are
and note that for example
PRPR are not square-free
- This is codegolf, shortest program wins, standard loopholes are closed.
- You may print the words or create them in memory.
- Your program may be written as a function.
The number of square-free ternary words of given length are in https://oeis.org/A006156