<jupyter_start><jupyter_text>Summary Problem 1Get gamma rate, epsilon rate, and power consumption (https://adventofcode.com/2021/day/3)<jupyter_code>def power_consumption(report_input):
    with open(report_input,'r') as input_text:
        report = input_text.read()
    report_list = report.splitlines()
    value_size = len(report_list[0])
    example_length = len(report_list)
    gamma = []
    gamma_dec = 0
    epsilon = []
    epsilon_dec = 0
    for j in range (0,value_size):
        x = 0
        for i in range (0,example_length):
            x = x + int(report_list[i][j])
            # print(x)
        if x < example_length/2:
            epsilon.append(1)
            gamma.append(0)
        else:
            epsilon.append(0)
            gamma.append(1)
        gamma_dec = gamma_dec + gamma[j]*pow(2,value_size-(j+1))
        epsilon_dec = epsilon_dec + epsilon[j]*pow(2,value_size-(j+1))
    print("gamma = ", gamma, ",\nepsilon = ", epsilon)
    print("gamma_dec = ", gamma_dec)
    print("epsilon_dec = ", epsilon_dec)
    answer = gamma_dec * epsilon_dec
    return(answer)
power_consumption("report.txt")<jupyter_output>gamma =  [1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0] ,
epsilon =  [0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1]
gamma_dec =  2346
epsilon_dec =  1749<jupyter_text>Problem 2Get oxygen generator rating, CO2 scrubber rating, and life support rating of the submarine (https://adventofcode.com/2021/day/3)<jupyter_code>def find_rating(report_input, mode):
    with open(report_input,'r') as input_text:
        report = input_text.read()
    report_list = report.splitlines()
    # separate a list of original data and a list that changes in the course of finding process
    item_list = report_list
    value_size = len(report_list[0])
    example_length = len(report_list)
    # separate the lenth of original data and that of a list that changes in the course of finding process
    total_items = example_length
    binary_value = []
    rating = 0
    # as "value_size" is anyways the max of the repetition, probably it is OK to use it rather than using while?
    for j in range (0, value_size):
        x = 0
        for i in range (0,total_items):
            # to show the value of j-th position of an i-th element in a list is element[i][j]
            x = x + int(item_list[i][j])
        # which is the most, either 1 or 0?
        if mode == "co2":
            if x >= total_items/2:
                binary_value.append(0)
            else:
                binary_value.append(1)
        else:
            if x >= total_items/2:
                binary_value.append(1)
            else:
                binary_value.append(0)            
        candidates = [item for item in item_list if int(item[j]) == binary_value[j]]
        item_list = candidates
        total_items = len(item_list)
        if len(item_list) == 1:
            print(item_list) 
            break
    for j in range (0, value_size):
        rating = rating + int(item_list[0][j])*pow(2,value_size-(j+1))
    if mode == "co2":
        print("co2_rating is ", rating)
    else:
        print("oxgen_rating is ", rating)
    return(rating)
life_support_rating = find_rating("report.txt","oxgen")*find_rating("report.txt","co2")
print(life_support_rating)<jupyter_output>['110101000111']
oxgen_rating is  3399
['010011100001']
co2_rating is  1249
4245351
StarcoderdataJupyterStructuredCleanDedup