Seems to me like you are checking from left to right whether there is a chance to swap in the main function?

If yes, then the problem is that to get the maximum reduction of damage, we should reduce the energy of the shooting that has been charged most, therefore it should be from right to left instead. Another thing is that maybe before you swap all shooting and charging that could be swapped in a loop, the damage has already been reduced to a value<=threshold. Therefore I suggest you to check after each swap. On Thursday, April 12, 2018 at 10:19:21 AM UTC-7, Sahil Shetty wrote: > def change(rcodeC, i): > > holder = rcodeC[i + 1] > rcodeC[i + 1] = rcodeC[i] > rcodeC[i] = holder > return rcodeC > > def damage(rcodeD, dmg = 0, count = 0): > > for i in rcodeD: > > if i == 'S': dmg += 2 ** count > else: count += 1 > > return dmg > > > def main(shield, rcode, hacks = 0, count = 0): > > while damage(rcode) > shield: > > for i in range(len(rcode) - 1): > > try: > > if rcode[i] == 'C' and rcode[i + 1] != 'C': > > hacks += 1 > rcode = change(rcode, i) > > try: > > if all(e == 'C' for e in rcode[rcode.index('C'): -1]) == > True and damage(rcode) > shield: return 'IMPOSSIBLE' > > except ValueError: > > if all(e == 'S' for e in rcode[rcode.index('S'): -1]) == > True and damage(rcode) > shield: return 'IMPOSSIBLE' > > except IndexError: None > > return hacks > > > test = int(raw_input("Test data: ")) > print '\n' > while test < 1 or test > 100: test = int(raw_input("Between 1 and 100: ")) > > for i in range(test): > > shield = int(raw_input("Shield strength: ")) > while shield < 1 or shield > (10 ** 9): shield = int(raw_input("Between 1 > and 10^9: ")) > > rcode = raw_input("Robot code: ") > while all(i == 'C' or i == 'S' for i in rcode) != True or len(rcode) > 30 > or len(rcode) < 2: rcode = raw_input("Must be greater than 2 and less than 1; > only 'C' and 'S': ") > > > print 'Case #' + str(i + 1) + ':', main(shield, list(rcode)), '\n\n\n' -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/b53e0bdf-6910-406f-90e4-e1667a902a5a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.