27 lines
653 B
Perl
27 lines
653 B
Perl
|
:- use_module(library(pio)).
|
||
|
:- 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([], []).
|