Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Use lru_cache(), Luke! solution in Clear category for Halloween Monsters by obone
MONSTERS = '''
skeleton
ghost
jack
vampire
witch
mummy
zombie
werewolf
frankenstein
'''
def halloween_monsters(spell: str) -> int:
from functools import lru_cache
combine = lambda w1, w2: ''.join(sorted(w1 + w2))
contain = lambda w1, w2: min(w1.count(c) // w2.count(c) for c in w2)
@lru_cache()
def maximum(u = ''): return \
max((1 + maximum(combine(u, w)) for w in MONSTERS.split()
if contain(spell, combine(u, w))), default = 0)
return maximum()
Oct. 19, 2019
Comments: