The Minion Game

  • + 0 comments

    Something a little bit different, the total possible score can be caluclated using the arithmetic series formula (total = (n * (n+1) ) // 2). This allows Stuart's score to be caluclated as every point that Kevin didn't get.

    Code:

    def minion_game(string):
        VOWELS = ['A','E','I','O','U']
        n = len(string)
        total = (n * (n+1) ) // 2
        
        kevin = 0
        for i, char in enumerate(string):
            if char in VOWELS:
                kevin += n - i
        stuart = total - kevin
        
        if stuart > kevin:
            print(f"Stuart {stuart}")
        elif stuart == kevin:
            print("Draw")
        elif stuart < kevin:
            print(f"Kevin {kevin}")