Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If a User never "wants" a type he "has" for counting the way it can be done combinatorics is enough, no algorithm needed. If you want to "show" the ways the swapping takes place, then :</p> <p>For visualizing the problem, arrange the types in the following way:</p> <pre><code> TYPE A ........................... TYPE N | | | | | | | | | USER 2 | | | | USER 1 | | | | USER 1 | +..........+ +----------+ HAS WANTS +----------+ | USER 3 | | USER 4 | | USER 5 | | | </code></pre> <p>So in our example User 1 has two Type A cards, user 2 has one, and users 3,4 and 5 wants one type A card each. </p> <p>Let's think at this moment of just Type A cards. </p> <p>You need to form pairs for exchanging cards such as the sequential one:</p> <pre><code> {{usr 1,usr3},{usr1, usr 4}, {usr2,usr5}} </code></pre> <p>If every user will be satisfied, there will be same owners than askers. </p> <p>Now, for forming pairs you know you have to pick one element of each set without reposition. As there may be repetitions (users wants or has more than one card of a type), you have to account for that also. This is for counting the ways each type should be "processed". And combinatorics is enough. </p> <p>For forming the pairs you may: </p> <p>1) Construct all different permutations of each set: </p> <pre><code> {2, 1, 1} {1, 2, 1} {1, 1, 2} # == 3!/2! {3, 4, 5} {5, 3, 4} {4, 5, 3} {4, 3, 5} {5, 4, 3} {3, 5, 4} # == 3! </code></pre> <p>2) For each pair of permutations you have a different result set 3 x 6 = 18 in our example. ....</p> <p>Do the same for all card types ...</p> <p>And finally you have N possible result sets for each card type. For getting ALL possible ways to exchange all the cards, you have to combine all possible ways for each type ... </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload