The Minion Game

Sort by

recency

|

1262 Discussions

|

  • + 0 comments

    The Minion Game is an engaging word game that tests players' vocabulary and quick thinking by pitting consonants against vowels. Its competitive structure and simple rules make it both fun and challenging, offering a great mental workout for all ages. Cricbet99 Register

  • + 0 comments
    def minion_game(string):
        vowel_indexes = [i for i in range(len(string)) if string[i] in ['A', 'E', 'I', 'O', 'U']]
        cons_indices = [i for i in range(len(string)) if string[i] not in ['A', 'E', 'I', 'O', 'U']]
        vowel_score = sum([len(string)-i for i in vowel_indexes])
        cons_score = sum([len(string)-i for i in cons_indices])
        if cons_score > vowel_score:
            return print("Stuart", cons_score)
        elif cons_score < vowel_score:
            return print("Kevin", vowel_score)
        else:
            return print("Draw")
    
  • + 1 comment

    Instead of generating all possible substrings and storing them in a dictionary, you can take advantage of the fact that you don't need the actual substrings. You just need to count the number of substrings that start with a vowel or consonant.

    To make it efficient:

    If you consider a character at position i in the string, the number of substrings that start at i is equal to n - i, where n is the length of the string. Based on this, if the character is a vowel, Kevin will get n - i points for that character. Similarly, if it is a consonant, Stuart will get n - i points for that character. This approach avoids explicitly generating substrings and directly calculates the scores.

    def minion_game(string):
        vowels = 'AEIOU'
        str_len = len(string)
        
        kevin_score = 0
        stuart_score = 0
    
        for i in range(str_len):
            if string[i] in vowels:
                kevin_score += str_len - i
            else:
                stuart_score += str_len - i
    
        if kevin_score > stuart_score:
            print(f'Kevin {kevin_score}')
        elif stuart_score > kevin_score:
            print(f'Stuart {stuart_score}')
        else:
            print('Draw')
    
  • + 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}")
    
  • + 0 comments
    def minion_game(string):
        # your code goes here
        vowel = ['A', 'E', 'I', 'O', 'U']
        
        vowel_pt = 0
        consonant_pt = 0
      
        
     
        for i in range(len(string)):
            if string[i] in vowel:
              vowel_pt += (len(string) - i)
            
            else:
                consonant_pt +=(len(string) - i)
                    
        if vowel_pt > consonant_pt:
            print("Kevin", vowel_pt)
        
        elif consonant_pt > vowel_pt:
            print("Stuart", consonant_pt)
        else:
            print("Draw")
                
        # print(score["Stuart"])
            
    
    if __name__ == '__main__':
        s = input()
        minion_game(s)