from itertools import combinations as comb
from functools import reduce
def all_arrangements(k):
m=k*(k+1)/2
m_bits_on=set([tuple(reduce(lambda x,y:x[:y]+[1]+x[y+1:],c,[0]*(2*m+1))) for c in comb(range(2*m+1),m)])
return set([tuple(sorted(filter(lambda i:i>0,reduce(lambda x,y: x+[y] if y==0 else x[:-1]+[x[-1]+1,],p,[0])))) for p in m_bits_on])
Returns all arrangements in the Bulgarian solitaire game with k piles https://en.wikipedia.org/wiki/Bulgarian_solitaire