2
$\begingroup$

Given an integer N, I want to represent every integer from 1 to N using a set of symbol combinations drawn from a predefined set of symbols $\mathbf S$ .

  • If $\mathbf S$ only has one character 'A', then 1 = 'A', 2 = 'AA', 3 = 'AAA' etc is the only possible solution.
  • If $\mathbf S$ has two characters 'A' and 'B', then 'B' can represent anything smaller than N. One solution is 1 = 'A', 2 = 'B', 3 = 'BA', 4 = 'BB'; or we can have 1 = 'A', 2 = 'AA', 3 = 'B', 4 = 'BA' and so on.

The representations are NOT permutations, i.e. 'BA' and 'AB' represent exactly the same number.

I am trying to find a solution that minimizes the total number of characters used specifically for the case N = 24 and $|\mathbf S|$ = 4.

Questions:

  1. Is there a systematic way to deduce the solution (e.g. using mathematical induction? But how can I do mathematical induction with two varying variables?)
  2. How can I proof that a solution is optimal? (any other solution will end up using more characters)
  3. Is it possible to generalize the solution to any N and any size of $\mathbf S$?

Note: I am not asking for the solution. Rather, I am asking for an approach which would lead me to find it.

  • 0
    As you know $N$ and $S$ I think the best way is to associate each number to a specific combination (with repetitions) of the elements in $S$. The first $|S|$ numbers will be associated to the single elements in $S$, the next $\binom{|S| + 1}{2}$ will be associated with the couples with repetitions, then we can associate the $\binom{|S| + 2}{3}$ triples, and so on. As we are using the shortest *strings* first you can demonstrate that the code will have the shortest length.2017-01-03
  • 0
    @N74: Depends on $N$ and $|S|$ I think. As long as elements of $S$ map to a value less than $N$, all singletons will be used regradless. And some of those couples-with-repetitions you describe are not unique; so perhaps a mapping where each couple covers a unique value could cover a larger range of $N$ before resorting to triples. Example: $N=8$, $S=\{1,2,3\}$ vs. $S = \{1,2,4\}$.2017-01-03
  • 1
    @chas you are assigning values to the elements in $S$, but thus is not what the OP intended. I'm not giving a value to the elements: for $N=8$ and $S={A,B,C}$ I have the sequence: A, B, C, AA, AB, AC, BC. The total number of chars is 11 and I don't think there is a shorter solution.2017-01-03
  • 0
    @N&4. Ah. Yes, in that case I think you are correct.2017-01-03
  • 0
    @N74 so if I select combinations like nC1, nC2 etc. until nC1 + nC2 + nC3 + ... >= N, that is the optimal solution?2017-01-03
  • 0
    Usually nC2 is used for the couples without repetitions, but I think you got the pattern.2017-01-03
  • 0
    @kevin: Actually, instead of nC1, nC2, etc., you'll need to answer the slightly different question: how many distinct strings of length $k$ using $m$ symbols (without considering order) are there? These are the same as the number of partitions of $k$ into $m$ bins.2017-01-03

0 Answers 0