28 lines
478 B
Python
28 lines
478 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
data = []
|
|
|
|
# parse input
|
|
input_file = open("input-ex1", "r")
|
|
pattern = []
|
|
for line in input_file:
|
|
for value in line.rstrip().split(","):
|
|
data.append(value)
|
|
input_file.close()
|
|
|
|
|
|
def get_hash(val):
|
|
h = 0
|
|
for b in value:
|
|
h += ord(b)
|
|
h *= 17
|
|
h %= 256
|
|
return h
|
|
|
|
|
|
hashsum = 0
|
|
for value in data:
|
|
print(value, get_hash(value))
|
|
hashsum += get_hash(value)
|
|
print("Hashsumme:", hashsum)
|