0

I am currently trying to solve a problem with constraint programming. My problem is that for example you need a set of numbers and you can only have a maximum number of 9 with a required length of 6 so you can get something like [1, 3, 4, 5, 6, 8] now when you sum up all these numbers you will get 27 but from the given variables above you can also get sum([1, 2, 3, 5, 7, 9]) and still get 27. But I am trying to get the exact [1, 3, 4, 5, 6, 8] so my current solution for this is to get a unique "trait" from the set of numbers I have, I've tried many solutions but all of them only works on small numbers for example :

I have this array called "shifts" this is equals to [1, 2, 3, 4, 5, 6, 7, 9] so I am going to multiply this with the set of numbers I have based on index for example

1 * 1 = 1
3 * 2 = 6
4 * 3 = 12
5 * 4 = 20
6 * 5 = 30
8 * 6 = 48
-----------
= 117

This is different from

1 * 1 = 1
2 * 2 = 4
3 * 3 = 9
5 * 4 = 20
7 * 5 = 35
9 * 6 = 54
----------
= 123

So now from my current constraint algorithm I can look for the number 117 to get the pattern I want. The problem is the chances of duplication rises the larger the numbers in your set of numbers and the larger your required length is so when I ran my algorithm it gives me another set of numbers that fits in the constraints I have given.

So are there any unique "traits" to get from the pattern that we are looking for? So far as stated from all the things I've tried I can only get the pattern I want if the set of numbers, and required length is small enough.

Note: Since I am using constraint programming I can't use division only floored division and no floats only integers

  • 2
    It sounds like you're looking for an injection from tuples of natural numbers to natural numbers. One way to do this is via prime factorization: $$[x_1,...,x_k]\mapsto \prod_{1\le i\le k}p_i^{x_i+1},$$ where $p_i$ is the $i$th prime (if you don't consider $0$ a natural number you don't need the "$+1$" bit, but otherwise it's needed to distinguish e.g. $[1,0]$ and $[1]$). This does lead to extremely large numbers; there are more efficient approaches. – Noah Schweber Aug 01 '22 at 02:13
  • Are the numbers in the array always unique and sorted? If so you can use the binary representation of your characteristic number to describe what elements it has. Otherwise, you might try concatenating the array into a number in nonary. – Angelica Aug 01 '22 at 02:14
  • As long as the numbers are less than $10$ you can just concatenate them to get $134568$ and can extract the numbers easily. If the numbers get larger you can use two digits at once or a larger base. If this doesn't work for you there is some constraint missing. – Ross Millikan Aug 01 '22 at 02:28

0 Answers0