|
123456789101112131415161718192021222324252627282930 |
- import sys
-
- def main():
- with open("aoc3-1.txt", "r") as file:
- inputs = [el.strip() for el in file.readlines()]
- digits = [[] for _ in range(len(inputs[0]))]
- for j, ip in enumerate(inputs):
- # print(digits, ip)
- for i, dg in enumerate(ip):
- # print(i, dg)
- dg = dg.strip()
- if dg != "":
- digits[i].append(int(dg))
-
- # if j >= 2:
- # sys.exit(0)
- gamma, epsilon = [], []
- for el in digits:
- gamma.append(1 if el.count(1) >= el.count(0) else 0)
- epsilon.append(0 if el.count(1) >= el.count(0) else 1)
- gamma_str = "".join([str(el) for el in gamma])
- epsilon_str = "".join([str(el) for el in epsilon])
- gamma_int = int(gamma_str, 2)
- epsilon_int = int(epsilon_str, 2)
- print(f"Gamma: {gamma_str} -- {gamma_int}")
- print(f"Epsilon: {epsilon_str} -- {epsilon_int}")
- print(f"Consumption: {gamma_int*epsilon_int}")
-
- if __name__ == "__main__":
- main()
|