@@ -0,0 +1,2615 @@
+# Google Code Jam%0A# Google Code Jam 2015%0A# Qualification Round%0A# Problem B. Infinite House of Pancakes%0A%0Afrom math import ceil%0A%0Aclass TestCase:%0A    def __init__(self):%0A        self.initialDinerCount = 0%0A        self.pancakes = 0%0A        %0AtestCaseFile = open(%22InfiniteHouseOfPancakes_B-small-practice.in%22, %22r%22)%0Alines = testCaseFile.read().split('%5Cn')%0An = int(lines%5B0%5D)%0AtestCases = %5B0 for x in range(n)%5D%0A%0Adef initialize_test_cases(lines):%0A    global testCases%0A    count = -1%0A    for index, item in enumerate(lines):%0A        if index %3E 0: %0A            if (index %25 2 %3E 0): %0A                count += 1%0A                if (count %3C n):%0A                    testCases%5Bcount%5D = TestCase()%0A                    initialDinerCount = int(item)%0A                    testCases%5Bcount%5D.pancakes = %5B0 for x in range(initialDinerCount)%5D%0A            else: %0A                p = item.split(' ')%0A                if (len(p) %3E 0):%0A                    for x in range(initialDinerCount):%0A                        testCases%5Bcount%5D.pancakes%5Bx%5D = int(p%5Bx%5D)%0A                        %0Adef compute_best_time(testCase):%0A    bestTime = 0%0A    pancakeCount = sum(testCase.pancakes)%0A    %0A    while (pancakeCount %3E 0):%0A        print(testCase.pancakes)%0A        maxPancake = max(testCase.pancakes)%0A        threshold = ceil(maxPancake / 2)%0A        %0A        countOverThreshold = sum(1 for x in testCase.pancakes if x %3E threshold)%0A        timeToThreshold = maxPancake - threshold%0A        %0A        if (maxPancake == 1):%0A            testCase.pancakes = %5B0 for x in testCase.pancakes%5D%0A            bestTime += 1%0A        elif (countOverThreshold %3E= timeToThreshold): %0A            testCase.pancakes = %5Bmax(x - 1, 0) for x in testCase.pancakes%5D%0A            bestTime += 1%0A            #testCase.pancakes = %5B0 for x in testCase.pancakes%5D%0A            #bestTime += maxPancake%0A        else: %0A            for x in range(len(testCase.pancakes)):%0A                if (testCase.pancakes%5Bx%5D %3E threshold):%0A                    newPancake = testCase.pancakes%5Bx%5D - ceil(testCase.pancakes%5Bx%5D / 2)%0A                    testCase.pancakes%5Bx%5D = ceil(testCase.pancakes%5Bx%5D / 2)%0A                    testCase.pancakes.append(newPancake)%0A            bestTime += countOverThreshold%0A        %0A        pancakeCount = sum(testCase.pancakes)%0A        #print(threshold)%0A        #print(countOverThreshold)%0A        #print(timeToThreshold)%0A        %0A    %0A    return bestTime%0A%0Adef print_all_results():%0A    for x in range(len(testCases)):%0A        print('Case #' + str(x + 1) + ': ' + str(compute_best_time(testCases%5Bx%5D)))%0A%0Ainitialize_test_cases(lines)%0Aprint_all_results()%0A#print(compute_best_time(testCases%5B68%5D))%0A

Create InfiniteHouseOfPancakes.py