Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Halloween Monsters by liw_80
MONSTERS = '''
skeleton
ghost
jack
vampire
witch
mummy
zombie
werewolf
frankenstein
'''
def halloween_monsters(spell: str)-> int:
monsters = MONSTERS.strip().split('\n')
tmp, out = 0, 0
for monster in monsters:
if all(True if m in spell and spell.count(m) >= monster.count(m) else False for m in monster):
tmp += 1
s = spell
for m in monster:
s = s.replace(m, '', 1)
tmp += halloween_monsters(s)
out = tmp if tmp > out else out
tmp = 0
return out
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.")
May 12, 2020
Comments: