summaryrefslogtreecommitdiff
path: root/articles/res/code1_j03_aoc.py
diff options
context:
space:
mode:
Diffstat (limited to 'articles/res/code1_j03_aoc.py')
-rw-r--r--articles/res/code1_j03_aoc.py20
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)
+