1

Given 'n', 'm', 'k', 'x' and 'y' integer values...
I have a numeric ArrayList with 'n' positions and I need to create 'k' other arrays using the values in the first array and with 'm' positions. How can I did it ensuring that the sum of the numbers is 'x' with a maximum margin of error of 'y' and the arrays to be as different as possible between them?

I will use this in a test generator to randomize the questions. The numbers represent the difficult of the questions. When I tried to do it I randomize situations and checked if they were correct, but that is very slow. Someone knows a better way to do this?

mmmmmm
  • 32,227
  • 27
  • 88
  • 117
Lucas Cleto
  • 195
  • 1
  • 16

3 Answers3

1

From Your description it sounds like a variation of Discrete Knapsack Problem. Basically You search for several solutions of a modifies DKP - if there will be more that k of them You can remove additional ones, if less - You can permute that ones You obtained to generate some more.

The naive implementation would be searching solutions of DKP from n = x-y to x+y, and then processing them as described above, it could be really slow though. You might obtain some better solution asking on Mathematics Stack Exchange.

Mateusz Kubuszok
  • 24,995
  • 4
  • 42
  • 64
0

You have some less than n! / (m! . (n-m)!) acceptable solutions, out of which to pick as most differing solutions.

  1. The possible candidate solutions adhere to an optimal cost of square of deviation to y.

  2. For a fixed number of possible solutions pick as definitive solution where the difference to prior accepted definitive solutions is minimal: sum of difficulties of same entries. (This is just locally optimal, but should do.)

Sort the n# list on decreasing difficulty. Iterate for m# sublists in principle for n! / (m! . (n-m)!).

Change take candidates with respect to the allowed range: skipping/failing on those out of range.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
0

First sort your array.then find value of the element that is closest to X/m that i call mid.

find m number closest to mid.or use this idea

So set source point equal mid:

for (int i=0; i < n ; i++)

{ a[i]=a[i]-mid }

now you need m numbers that the sum of the numbers is zero,see link1&link2&link3 maybe useful. for better guidance please explain that what it is your mean that the arrays to be as different as possible between them.

Community
  • 1
  • 1
amin k
  • 1,692
  • 1
  • 12
  • 28