Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Halloween Monsters by pokosasa
MONSTERS = '''
skeleton
ghost
jack
vampire
witch
mummy
zombie
werewolf
frankenstein
'''
from itertools import combinations_with_replacement
from collections import Counter
def halloween_monsters(spell: str)-> int:
c_spell=Counter(spell)
c_monsters=[Counter(monster) for monster in MONSTERS.split()]
max_calls=len(spell)//len("jack")
for i in range(1,max_calls+1):
for names in combinations_with_replacement(c_monsters,i):
c_names=sum(names,Counter())
if c_spell-c_names+c_names==c_spell:
break
else:
return i-1
return max_calls
if __name__ == '__main__':
assert halloween_monsters('casjokthg') == 2, 'jack ghost'
assert halloween_monsters('leumooeeyzwwmmirbmf') == 3, 'mummy zombie werewolf'
assert halloween_monsters('nafrweiicttwneshhtikcn') == 3, 'witch witch frankenstein'
assert halloween_monsters('kenoistcepajmlvre') == 2, 'skeleton vampire (not jack)'
assert halloween_monsters('miaimavrurymepepv') == 2, 'vampire vampire (not mummy)'
print("Your spell seem to be okay. It's time to check.")
Dec. 15, 2019
Comments: