From a4e02c42a7ba35f006a59bc166baf230b5510d0d Mon Sep 17 00:00:00 2001 From: setop Date: Sat, 16 Dec 2023 00:26:27 +0100 Subject: [PATCH] day 15, factor both parts --- d15/part1.py | 12 ------------ d15/{part2.py => run.py} | 6 +++++- 2 files changed, 5 insertions(+), 13 deletions(-) delete mode 100644 d15/part1.py rename d15/{part2.py => run.py} (86%) diff --git a/d15/part1.py b/d15/part1.py deleted file mode 100644 index f07eaba..0000000 --- a/d15/part1.py +++ /dev/null @@ -1,12 +0,0 @@ -import sys - -S=0 -for l in sys.stdin.read().split(','): - c = 0 - for w in l: - c += ord(w) - c *= 17 - c = c % 256 - print(l, c) - S += c -print(S) diff --git a/d15/part2.py b/d15/run.py similarity index 86% rename from d15/part2.py rename to d15/run.py index d1ef39c..a9c5765 100644 --- a/d15/part2.py +++ b/d15/run.py @@ -8,9 +8,13 @@ def hash(l): c = c % 256 return c +L = sys.stdin.read().split(',') + +print(sum(hash(l) for l in L)) + B = [ dict() for _ in range(256) ] -for l in sys.stdin.read().split(','): +for l in L: e = l.find('=') d = l.find('-') i = max(e,d)