28 lines
684 B
Perl
28 lines
684 B
Perl
|
:- use_module(library(pio)).
|
||
|
:- use_module(library(clpfd)).
|
||
|
:- initialization(main, main).
|
||
|
|
||
|
main([FileName|_]) :-
|
||
|
input(FileName, Input),
|
||
|
hashes(Input, Hash),
|
||
|
writef('Answer=%t\n', [Hash]).
|
||
|
|
||
|
hashes(Strs, Hash) :-
|
||
|
concurrent_maplist(reverse, Strs, RStrs),
|
||
|
concurrent_maplist(hash, RStrs, Hashes),
|
||
|
sum_list(Hashes, Hash).
|
||
|
|
||
|
hash([], 0).
|
||
|
hash([C|Str], Hash) :- hash(Str, Prev), Hash is (Prev + C)*17 mod 256.
|
||
|
|
||
|
% Input stuff
|
||
|
input(FileName, Input) :- phrase_from_file(string(Input), FileName).
|
||
|
|
||
|
string([]) --> (eos; "\n"), !.
|
||
|
string([Item|Items]) --> item(Item), string(Items).
|
||
|
|
||
|
item([]) --> (","; "\n"; eos), !.
|
||
|
item([C|Chars]) --> [C], item(Chars).
|
||
|
|
||
|
eos([], []).
|