Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
recursion solution in Clear category for Halloween Monsters by kdim
MONSTERS = ['skeleton', 'ghost', 'jack', 'vampire', 'witch', 'mummy', 'zombie', 'werewolf', 'frankenstein']
def halloween_monsters(spell: str) -> int:
m = 0
for monster in MONSTERS:
if all(spell.count(i) >= monster.count(i) for i in monster):
s = spell
for i in monster:
s = s.replace(i, '', 1)
m = max(m, halloween_monsters(s) + 1)
return m
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.")
Jan. 2, 2023
Comments: