The special score(ssc) of an array of integers will be the sum of each integer multiplied by its corresponding index plus one in the array.

E.g.: with the array  ```[6, 12, -1]```
```
arr =   [6,      12,       -1 ]
ssc =   1*6  +  2* 12 +  3.(*1) = 6 + 24 - 3 = 27
```
The array given in the example has six(6) permutations and are with the corresponding ssc:
```
Permutations      Special Score (ssc)
[6, 12, -1]      1*6 + 2*12 + 3*(-1) = 27
[6, -1, 12]       1*6 + 2*(-1) + 3*12 = 40
[-1, 6, 12]       1*(-1) + 2*6 + 3*12 = 47
[-1, 12, 6]       1*(-1) + 2*12 + 3*6 = 41
[12, -1, 6]       1*12 + 2*(-1) + 3*6 = 28
[12, 6, -1]       1*12 + 2*6 + 3*(-1) = 21
```
The total sum of the ```ssc's``` of all the possible permutations is: ```27 + 40 + 47 + 41 + 28 + 21 = 204```

The maximum value for the ```ssc``` is ```47```.

The minimum value for the ```ssc``` is ```21```.

We need a special function ```ssc_forperm()``` that receives an array of uncertain number of elements (the elements may occur more than once) and may output a list of dictionaries with the following data:
```
[{"total perm":__}, {"total ssc": ___}, {"max ssc": __}, {"min ssc": __}]
```
For the example we have above will be:
```python
ssc_forperm([6, 12, -1]) = [{"total perm":6}, {"total ssc:204}, {"max ssc":47}, {"min ssc":21}]
```
You may assume that you will never receive an empty array.

Also you will never receive an array with the same element in all the positions like [1, 1, 1, 1 ,1], but you may have elements occuring twice or more like [1, 1, 1, 2, 3]

Enjoy it!!

Difficulty: EASY
Tags: Fundamentals

Combinatorics

Data structures

Mathematics
Skill types: Data structures

Starter code:
def ssc_forperm(arr):
	

Solutions:
from itertools import permutations

def ssc_forperm(arr):
	perms = set((p for p in permutations(arr)))
	values = [sum(((x + 1) * y for (x, y) in enumerate(i))) for i in perms]
	return [{'total perm': len(perms)}, {'total ssc': sum(values)}, {'max ssc': max(values)}, {'min ssc': min(values)}]


from collections import Counter
from math import factorial
import operator

def ssc_forperm(xs):
	n = len(xs)
	p = factorial(n) // reduce(operator.mul, map(factorial, Counter(xs).itervalues()))
	sxs = sorted(xs)
	return [{'total perm': p}, {'total ssc': (n + 1) * p * sum(xs) // 2}, {'max ssc': sum((i * x for (i, x) in enumerate(sxs, 1)))}, {'min ssc': sum((i * x for (i, x) in enumerate(reversed(sxs), 1)))}]


def ssc_forperm(arr):
	from itertools import permutations, count, imap
	from operator import mul
	perms = list(set(permutations(arr)))
	scc = [sum(imap(mul, i, count(1))) for i in perms]
	return [{'total perm': len(scc)}, {'total ssc': sum(scc)}, {'max ssc': max(scc)}, {'min ssc': min(scc)}]


from math import factorial as f
ssc_forperm = lambda arr: (lambda fac: [{'total perm': fac}, {'total ssc': fac * (len(arr) + 1) / 2 * sum(arr)}, {'max ssc': sum([(i + 1) * a for (i, a) in enumerate(sorted(arr))])}, {'min ssc': sum([(i + 1) * a for (i, a) in enumerate(sorted(arr, reverse=True))])}])(f(len(arr)) / reduce(lambda a, b: a * b, [f(arr.count(x)) for x in set(arr)]))
from functools import reduce


from math import factorial as fact
from collections import Counter
from functools import reduce

def ssc_forperm(arr):
	cnt = Counter(arr)
	nPerms = fact(len(arr)) // reduce(int.__mul__, map(fact, cnt.values()), 1)
	sIdx = -~len(arr) * len(arr) >> 1
	arr = sorted(arr)
	return [{'total perm': nPerms}, {'total ssc': sum((v * sIdx * nPerms // len(arr) for v in arr))}, {'max ssc': sum((v * i for (i, v) in enumerate(arr, 1)))}, {'min ssc': sum((v * i for (i, v) in enumerate(reversed(arr), 1)))}]


from itertools import permutations

def ssc_forperm(lst):
	scores = [sum((i * n for (i, n) in enumerate(p, 1))) for p in set(permutations(lst))]
	return [{'total perm': len(scores)}, {'total ssc': sum(scores)}, {'max ssc': max(scores)}, {'min ssc': min(scores)}]


from collections import Counter
from itertools import permutations
from math import factorial
from operator import mul

def ssc(xs):
	return sum((i * x for (i, x) in enumerate(xs, 1)))

def ssc_forperm(arr):
	m = reduce(mul, (factorial(x) for x in Counter(arr).values()))
	xs = [ssc(xs) for xs in permutations(arr)]
	return [{'total perm': len(xs) // m}, {'total ssc': sum(xs) // m}, {'max ssc': max(xs)}, {'min ssc': min(xs)}]


from itertools import permutations

def ssc_forperm(arr):
	maximum = -999999999
	minimum = 999999999
	total_score = [{'total perm': 0}, {'total ssc': 0}, {'max ssc': 0}, {'min ssc': 0}]
	lend = len(set(list(permutations(arr))))
	permutated_list = list(set(permutations(arr)))
	for element in permutated_list:
		temp = 0
		for (e, i) in enumerate(element, start=1):
			temp += e * i
		total_score[1]['total ssc'] += temp
		if temp > maximum:
			maximum = temp
			total_score[2]['max ssc'] = maximum
		if temp < minimum:
			minimum = temp
			total_score[3]['min ssc'] = minimum
	total_score[0]['total perm'] = lend
	return total_score