From 9407e73b44da353ff83a36d06298259786d9a174 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 15 Dec 2023 10:58:59 +0000 Subject: [PATCH] 2023: d15: ex1: add solution --- 2023/d15/ex1/ex1.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 2023/d15/ex1/ex1.py diff --git a/2023/d15/ex1/ex1.py b/2023/d15/ex1/ex1.py new file mode 100755 index 0000000..41fbc25 --- /dev/null +++ b/2023/d15/ex1/ex1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +import sys + + +def solve(input: list[str]) -> int: + def compute_hash(string: str) -> int: + res = 0 + + for c in string: + res += ord(c) + res *= 17 + res %= 256 + + return res + + return sum(map(compute_hash, input)) + + +def main() -> None: + input = sys.stdin.read().splitlines() + assert len(input) == 1 # Sanity check + print(solve(input[0].split(","))) + + +if __name__ == "__main__": + main()