diff options
author | ache <ache@ache.one> | 2021-12-29 04:42:44 +0100 |
---|---|---|
committer | ache <ache@ache.one> | 2021-12-29 04:42:56 +0100 |
commit | 5e987c201b4b20d4034b2f72edd528e75939ffcd (patch) | |
tree | 972625be0f0e17656b4e29a6705e0f2e46e3b595 /articles/res/code1_j03_aoc.py | |
parent | Ajout du logo (diff) |
Remplacement des secrets par des ressources externes
Diffstat (limited to 'articles/res/code1_j03_aoc.py')
-rw-r--r-- | articles/res/code1_j03_aoc.py | 20 |
1 files changed, 20 insertions, 0 deletions
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) + |