Skip to content
Advertisement

Minion game- Explain?


  1. I cannot understand how this logic is able to find out the permutations of every letter and able find its value/score. Can someone please explain this code? Both players are given the same string, . Both players have to make substrings using the letters of the string . Stuart has to make words starting with consonants. Kevin has to make words starting with vowels. The game ends when both players have made all possible substrings.

Scoring A player gets +1 point for each occurrence of the substring in the string .

For Example: String = BANANA Kevin’s vowel beginning word = ANA

Here, ANA occurs twice in BANANA. Hence, Kevin will get 2 Points.

    s = raw_input()
    vowels = 'AEIOU'  
    kevsc = 0
    stusc = 0
    for i in range(len(s)):
        if s[i] in vowels:
            kevsc += (len(s)-i)
        else:
            stusc += (len(s)-i)    
    if kevsc > stusc:
        print "Kevin", kevsc
    elif kevsc < stusc:
        print "Stuart", stusc
    else:
        print "Draw"

Advertisement

Answer

I don’t quite know what you mean by “find out the permutations of every letter”, but this code is not doing anything related to permutations. What it is doing doesn’t seem to make much sense.

It goes through the input string, and awards points to Kevin for each uppercase vowel, and Stuart for each other character. The number of points awarded in each case is equal to distance of the letter from the end of the input string, e.g. in the string “AB”, Kevin will get 2 points for the A (because it is an uppercase vowel 2nd to last) and Stuart will get 1 point for B (because it is not an uppercase vowel, and it is last).

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement