Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Recursive generator solution in Clear category for Halloween Monsters by swagg010164
from collections import defaultdict
MONSTERS = '''
skeleton
ghost
jack
vampire
witch
mummy
zombie
werewolf
frankenstein
'''
def word_returner(data, carry):
for k in carry:
data[k] += 1
return data
def word_finder(data, word):
for k in word:
if data[k] > 0:
data[k] -= 1
else:
return
return data
def recur(count, data, carry=""):
for k in MONSTERS.split():
if word_finder(data.copy(), k):
data = word_finder(data, k)
yield from recur(count + 1, data, k)
yield count
data = word_returner(data, carry)
count -= 1
def halloween_monsters(spell: str) -> int:
data = defaultdict(int)
for k in spell:
data[k] += 1
return max(recur(0, data))
Jan. 1, 2020
Comments: