The Minion Game

  • + 0 comments

    I had some trouble with run time errors initially, I was making it way more complex than it had to be. I find it helpful to note that the number of subsets starting with a letter is: the length of the string - the index of the letter. I.e. if the string is 'banana', the number of subsets starting with 'b' is len('banana')-index('b') = 6-0 = 6 : [b, ba, ban, bana, banan, banana]

    Using this method you can add the number of subsets starting with each vowel, and the same with each non-vowel.

    for i in range(len(string)):
        if string[i] in v:
            c1 = c1 + len(string) - i
        else:
            c2 = c2 + len(string) - i
    

    You could also make two seperate lists - one with the indicies of each vowel, and one with the indicies of each non-vowel. Then get the scores by calculating the length of the string * length of the list of indicies - sum of the list of indicies.

    for i in range(len(string)):
        if string[i] in v:
            a.append(i)
        else:
            b.append(i)
    c1 = len(string)*len(a) - sum(a)  
    c2 = len(string)*len(b) - sum(b)
    

    Then you can determine the winner by comparing the scores.