From 5e987c201b4b20d4034b2f72edd528e75939ffcd Mon Sep 17 00:00:00 2001 From: ache Date: Wed, 29 Dec 2021 04:42:44 +0100 Subject: Remplacement des secrets par des ressources externes --- articles/res/code1_j03_aoc.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 articles/res/code1_j03_aoc.py (limited to 'articles/res/code1_j03_aoc.py') diff --git a/articles/res/code1_j03_aoc.py b/articles/res/code1_j03_aoc.py new file mode 100644 index 0000000..f4c36e7 --- /dev/null +++ b/articles/res/code1_j03_aoc.py @@ -0,0 +1,20 @@ +gamma, epsi = 0, 0 +total = 1 + +with open("input") as f: + final = f.readline().strip() + final = list(map(lambda x: 1 if x == '1' else 0, final)) + print(final) + + for line in f: + for i, c in enumerate(line): + if c == '1': + final[i] += 1 + total += 1 + +gamma = int("".join(list(map(lambda x: '1' if total - x > x else '0', final))), 2) +epsi = int("".join(list(map(lambda x: '0' if total - x > x else '1', final))), 2) + + +print(epsi, gamma, gamma * epsi) + -- cgit v1.2.3