0
$\begingroup$

I have a list of n objects

say [ apple, orange, carrot, cherry, banana ]

Now I am trying to come up with an equation which will generate an unique number for each combinations from this list.

eg :

say I assign following values for each items

apple = 1
orange = 2
carrot = 3
cherry = 4
banana = 5

If I directly add the individual values to generate combination score then the values will be

apple      = 1
apple, carrot = 4
apple, orange = 3

But here multiple combination can have same scores.

I need to generate an equation which will generate UNIQUE score for all of these combination.

POSITION IS NOT AN ISSUE.

Score(apple,orange,carrot) = Score(carrot, apple, orange) = Score (orange, apple, carrot)

But Score (apple, carrot) $\ne$ Score(cherry)

How this can be generated ?

$\endgroup$
  • $\begingroup$ Welcome to math.SE: since you are new, I wanted to let you know a few things about the site. In order to get the best possible answers, it is helpful if you write what your thoughts are on the problem and include your efforts (work in progress) in this and future posts; this will prevent people from telling you things you already know, and help them give their answers at the right level. $\endgroup$ – JKnecht Feb 5 '16 at 12:21
  • $\begingroup$ Why not just combine them into a single number, e.g. apple, orange and carrot ($1$ and $2$ and $3$) becomes $123$. Or, mathematically, multiply each number with $10^i$, with $i$ their position, starting count at $0$. $\endgroup$ – Eric S. Feb 5 '16 at 12:46
  • $\begingroup$ Eric, then apple, orange and carrot (1 and 2 and 3) = 123 and orange, apple and carrot (2 and 1 and 3) = 213 are not equal $\endgroup$ – Sreejithc321 Feb 6 '16 at 10:47
1
$\begingroup$

Assign a prime number to each object.

Let the score for each combination be the product of the prime numbers assigned to the objects in the combination.

This will also allow you to use the score to record multiple occurrences of items (if you want).

Every such score created can be uniquely factorised to identify the items in your list.

$\endgroup$
  • $\begingroup$ Yes this works, thank you. Is there a better way if the number of objects in list > 10000. Because then the product will be so huge. $\endgroup$ – Sreejithc321 Feb 5 '16 at 12:53
  • $\begingroup$ That's because the number of different combinations is so large! $\endgroup$ – tomi Feb 5 '16 at 14:54
  • $\begingroup$ yes but still can this value be reduced some how ? $\endgroup$ – Sreejithc321 Feb 8 '16 at 10:30
  • $\begingroup$ How many objects are there likely to be in a typical "combination"? Do certain objects appear more frequently? Are there some pairings that appear more frequently than others? Are there some prohibited pairings? $\endgroup$ – tomi Feb 8 '16 at 10:40
2
$\begingroup$

Perhaps I'm missing something, but it sounds as if all you want is to assign each element a unique exponentiation of a base value; for example,

  • apple = 1 i.e. $2^0$
  • banana = 2 i.e. $2^1$
  • cherry = 4 i.e. $2^2$

etc. Then any way you add them, you can always decompose the sum. More simply:

  • apple = 1
  • banana = 10
  • cherry = 100
$\endgroup$
  • $\begingroup$ Welcome to math.SE! See this guide for how to mark up math nicely on this site. $\endgroup$ – Frentos Feb 5 '16 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.