I did think of a direct algorithm, which I offer without proof, (and

written in j). First, understand how to use eliminate. Call it repeatedly until the key length is reduced sufficiently. This hidden comment

# find least used object (1 only)

indicates that the function drops only one object from the keys per call.

Code:

>>> d = {'ABCD':3,'ACBD':2,'BDCA':4,'DCBA':3,'CBAD':1,'CDAB':1,}
>>> eliminate(d)
{('B', 'D', 'A'): 4, ('A', 'B', 'D'): 5, ('D', 'A', 'B'): 1, ('B', 'A', 'D'): 1, ('D', 'B', 'A'): 3}
>>> eliminate(eliminate(d))
{('B', 'A'): 8, ('A', 'B'): 6}
>>> eliminate(eliminate(eliminate(d)))
{('B',): 14}
>>> eliminate(eliminate(eliminate({'ABCD':3,'ACBD':2,'BDCA':4,'DCBA':3,'CBAD':1,'CDAB':1,})))
{('B',): 14}
>>> ##### found your answer B
>>> ##Now try to rank ABC and D
>>> eliminate(eliminate({'ACD':3,'ACD':2,'DCA':4,'DCA':3,'CAD':1,'CDA':1,})) # remove B and try again
{('C',): 7}
>>> eliminate({'AD':3,'AD':2,'DA':4,'DA':3,'AD':1,'DA':1,}) # remove C, try again
{('D',): 2}
>>> # remove D, leaving A. The ranking becomes BCDA
>>>

The direct algorithm (which as of yesterday I thought didn't work. Today I see it works for your example.) I'll explain the algorithm with two of your test dictionary entries:

'ABCD':3, 'BDCA':4,

Assign weights to the objects in the key by position and multiply by the value

Code:

In 'ABCD':3,
A gets 4 * 3 = 12
B gets 3 * 3 = 9
C gets 2 * 3 = 6
D gets 1 * 3 = 3
for 'BDCA':4
B gets 4 * 4 = 16
D gets 3 * 4 = 12 D is 2nd. Assign weight 3. d['BDCA'] is the factor 4
C gets 2 * 4 = 8
A gets 1 * 4 = 4

Find a value for each object by sum over all occurrences:

A 16 = 12+4

B 25 = 16+9

C 14 = 8+6

D 15 = 12+3

Here's the verb and example. At the end you'll see that it determines the order BCDA.

Code:

rankThem=: monad define
KEYS=. 0 {::"1 y NB. Array of keys
FREQ=. 1 {::"1 y NB. Array of values
O=. ~. , KEYS NB. O is the set of objects in the keys
WEIGHTS=. KEYS (#@:] - i."1) O
R=. FREQ +/ .* WEIGHTS
O ;&:,. R
)
[D=: ('ABCD';3),('ACBD';2),('BDCA';4),('DCBA';3),('CBAD';1),:('CDAB';1)
┌────┬─┐
│ABCD│3│
├────┼─┤
│ACBD│2│
├────┼─┤
│BDCA│4│
├────┼─┤
│DCBA│3│
├────┼─┤
│CBAD│1│
├────┼─┤
│CDAB│1│
└────┴─┘
rankThem D
┌─┬──┐
│A│31│
│B│39│
│C│37│
│D│33│
└─┴──┘

agrees