The Minion Game

Sort by

recency

|

1272 Discussions

|

  • + 0 comments
    def minion_game(string):
        vowels = "AEIOU"
        Kevin_score = 0
        Stuart_score = 0
        
        for i in range(len(string)):
            if string[i] in vowels:
                Kevin_score += len(string) - i
            else:
                Stuart_score += len(string) - i
        
        if Stuart_score > Kevin_score:
            print("Stuart", Stuart_score)
        elif Stuart_score == Kevin_score:
            print("Draw")
        else:
            print("Kevin", Kevin_score)
    
  • + 0 comments
    from collections import Counter
    
    vowels = "AEIOU"
    
    def minion_game(txt):
        # your code goes here
        length = len(txt)
        score = Counter()
        for i, ch in enumerate(txt):
            points = length - i
            score[ch in vowels] += points  
        # print(score)
        
        if (kevin := score[True]) > (stuart := score[False]):
            print(f"Kevin {kevin}")
        elif stuart > kevin:
            print(f"Stuart {stuart}")
        else:
            print("Draw")
                
    # Input (stdin)
    # BANANA
    # Expected Output
    # Stuart 12
    
  • + 0 comments

    stuart = 0 Kevin = 0

    vowels = ['A','E', 'I', 'O', 'U']
    
    for x in range(len(string)):
        if(string[x] not in vowels):
            stuart+= len(string)-x;
        else:
            Kevin+= len(string)-x;
    
    
    if(stuart > Kevin):
        print ('Stuart ' + str(stuart))
    elif (Kevin > stuart):
        print ('Kevin ' + str(Kevin))
    else:
        print('Draw')
    
  • + 0 comments

    Wow, first I created a list with all the words, it worked for the example, but the validation has strings that are VERY long so my code was slow. I then realized I just need to count how many letters are in between the starting points and the end of the word.

    like for Banana, let's say starting point is the first "a"

    possible words: a an ana anan anana

    --> add 5 to score = len(string[start:]) or len(range(start, N))

    which is much more efficient.

    import re
    
    def minion_game(string):
        
        def get_score(pattern, string):
            score = 0
            N = len(string)
            for match in re.finditer(pattern, string, re.IGNORECASE):
                start = match.start()
                score += len(range(start, N))
            return score
        
        pattern_vowels = r"(?=[aeiou])"  # Use a capturing group inside a lookahead
        pattern_consonants = r"(?=[bcdfghjklmnpqrstvwxyz])"
        
        score_stuart = get_score(pattern_consonants, string)
        score_kevin =  get_score(pattern_vowels, string)
        if score_kevin > score_stuart:
            print ("Kevin", score_kevin)
        elif score_stuart > score_kevin:
            print("Stuart", score_stuart)
        else:
            print("Draw")
    
  • + 1 comment
    def minion_game(string):
        l = len(string)
        s,k = 0,0
        for i in range(l):
            if string[i] in "AEIOU":
                k+=l-i
            else:
                s+=l-i
        #print(*("Stuart",s) if s>k else ("Kevin",k) if k>s else ("Draw",))
        print(f"Stuart {s}" if s>k else f"Kevin {k}" if k>s else "Draw")
        
                    
    
    if __name__ == '__main__':
        s = input()
        minion_game(s)