Last active
April 3, 2018 18:56
-
-
Save reflechant/3e3efc813b0b1f62a0db5a422d356eef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import collections | |
import operator | |
import itertools | |
random.seed() | |
l = [random.randint(1, 18) for i in range(8)] | |
#l = [4, 8, 18, 18, 10, 3, 11, 18] | |
print(*l) | |
c = collections.Counter(l) | |
by_frequency = sorted(c.items(), key=operator.itemgetter(1), reverse=True) | |
gens = [itertools.repeat(x[0], x[1]) | |
for x in by_frequency] | |
chain = itertools.chain.from_iterable(gens) | |
parts = [[] for i in range(by_frequency[0][1])] | |
ring = itertools.cycle(parts) | |
for x, y in zip(ring, chain): | |
x.append(y) | |
answer = list(itertools.chain.from_iterable(parts)) | |
print(*answer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment