Easy one today. And on the first day I switched to python
This commit is contained in:
22
day_15/part1.py
Normal file
22
day_15/part1.py
Normal file
@@ -0,0 +1,22 @@
|
||||
def test(input, solution):
|
||||
print(f"Running input {input}")
|
||||
result = process(input)
|
||||
print(f"Solution was {result}")
|
||||
assert result == solution
|
||||
|
||||
def run():
|
||||
file = open("input.txt", "r")
|
||||
return process(file.read()[:-1])
|
||||
|
||||
def hash_value(word):
|
||||
count = 0
|
||||
for character in word:
|
||||
count += ord(character)
|
||||
count *= 17
|
||||
count = count % 256
|
||||
return count
|
||||
|
||||
def process(input):
|
||||
words = input.split(",")
|
||||
hashes = [hash_value(word) for word in words]
|
||||
return sum(hashes)
|
||||
Reference in New Issue
Block a user