2023: d15: ex1: add solution
This commit is contained in:
parent
1e7d41b861
commit
38dc59b16d
27
2023/d15/ex1/ex1.py
Executable file
27
2023/d15/ex1/ex1.py
Executable file
|
@ -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()
|
Loading…
Reference in a new issue