Santa Claus is only one of many members of the Claus family. Each of the members of the family has a unique name, based on the following rules.
For instance, valid names are SAM, SMAHA, MNTA, and ANH, but invalid are AM, SNT, SAATA, and AMNTH.
How many members does the Claus family have at most?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
We generate all 2 8 = 2 5 6 possible strings that can be obtained by leaving out letters, then check each string to see if it complies with all the rules.
However, this results in counting certain strings twice; e.g. SAHA can be made using either the first or the second A in SAMANTHA.
One way to avoid this is by keeping a list of generated names and discarding duplicates. I use a different strategy: when arriving at the letter A, if I skipped the previous A without including a letter in between, I discard the solution.
Technical detail/trick: The pattern of including/skipping letters is obtained from the bits of n , which runs from 0 0 0 0 0 0 0 0 2 (empty string) to 1 1 1 1 1 1 1 1 2 (all of SAMANTHA).
Output: