Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
collections.Counter and a bit of itertools solution in Clear category for Halloween Monsters by Phil15
from collections import Counter
import itertools as it
MONSTERS = ('frankenstein', 'ghost', 'jack', 'mummy', 'skeleton',
'vampire', 'werewolf', 'witch', 'zombie')
def halloween_monsters(spell: str) -> int:
spell = Counter(spell)
monsters = {
monster: range(next(n for n in it.count(1) if mul(count, n) - spell))
for monster in MONSTERS if not (count := Counter(monster)) - spell}
best = 0, {}
for sol in it.product(*monsters.values()):
if sum(sol) > best[0]:
count = sum((mul(Counter(name), nb)
for nb, name in zip(sol, monsters) if nb), Counter())
if not count - spell:
best = sum(sol), ' '.join(monster
for monster, nb in zip(monsters, sol)
for _ in range(nb))
print(best[1])
return best[0]
def mul(count: Counter, n: int) -> Counter: return sum([count] * n, Counter())
March 12, 2020
Comments: