from aocd import get_data from aocd import submit input_data = get_data(day=3, year=2021) test_data = """00100 11110 10110 10111 10101 01111 00111 11100 10000 11001 00010 01010""" lines = input_data.split("\n") # lines = test_data.split("\n") line_len = len(lines[0]) counts_ones = [0] * line_len counts_zeroes = [0] * line_len for line in lines: power = list(line) power = [int(i) for i in power] for index, bit in enumerate(power): if bit == 1: counts_ones[index] += 1 elif bit == 0: counts_zeroes[index] += 1 print(counts_ones) print(counts_zeroes) #loop through bits and find highest lowest gamma = [0] * line_len epsilon = [0] * line_len for i in range(line_len): print(i) if counts_ones[i] > counts_zeroes[i]: gamma[i] = 1 epsilon[i] = 0 elif counts_ones[i] < counts_zeroes[i]: gamma[i] = 0 epsilon[i] = 1 # print(gamma) # print(epsilon) gamma = ''.join(str(i) for i in gamma) epsilon = ''.join(str(i) for i in epsilon) powerconsumption = int(gamma, 2) * int(epsilon, 2) print(powerconsumption) # submit(depth*horizontal)