• + 1 comment

    Here is my Python solution! If we have at least one empty square, then we can move any of the ladybugs anywhere. This means that the only cases that work are if there are more than one empty square and an even number of each type, or if there are no empty squares but all the ladybugs are already happy.

    def ishappy(b):
        for bug in range(1, len(b) - 1):
            if b[bug] == b[bug - 1] or b[bug] == b[bug + 1]:
                continue
            else:
                return False
        return True
    
    def happyLadybugs(b):
        ladybugs = set([string for string in b if string != "_"])
        if list(b).count("_") < 1 and not ishappy(b):
            return "NO"
        for ladybug in ladybugs:
            if list(b).count(ladybug) < 2:
                return "NO"
        return "YES"
    
    • + 0 comments

      your code says yes to this, but it should be a no: ZAABBZ