better d16p2
This commit is contained in:
parent
793bb420ea
commit
2202ebf4a8
15
16/part2.pl
15
16/part2.pl
@ -5,12 +5,15 @@ main([FileName|_]) :-
|
|||||||
input(FileName, Map),
|
input(FileName, Map),
|
||||||
length(Map, Height), MaxX is Height - 1,
|
length(Map, Height), MaxX is Height - 1,
|
||||||
Map = [Row|_], length(Row, Width), MaxY is Width - 1,
|
Map = [Row|_], length(Row, Width), MaxY is Width - 1,
|
||||||
findall(N, (between(0, MaxX, X), propagate(Map, [X-0-3], End), count(End, N)), N1), nl,
|
findall([X-0-3], between(0, MaxX, X), S1),
|
||||||
findall(N, (between(0, MaxX, X), propagate(Map, [X-MaxY-1], End), count(End, N)), N2), nl,
|
findall([X-MaxY-1], between(0, MaxX, X), S2),
|
||||||
findall(N, (between(0, MaxY, Y), propagate(Map, [0-Y-0], End), count(End, N)), N3), nl,
|
findall([0-Y-0], between(0, MaxY, Y), S3),
|
||||||
findall(N, (between(0, MaxY, Y), propagate(Map, [MaxX-Y-2], End), count(End, N)), N4), nl,
|
findall([MaxX-Y-2], between(0, MaxY, Y), S4),
|
||||||
append([N1, N2, N3, N4], Ns), max_list(Ns, Answer),
|
append([S1, S2, S3, S4], Starts),
|
||||||
write(Answer), nl.
|
concurrent_maplist(
|
||||||
|
{Map}/[S, N]>>(propagate(Map, S, End), count(End, N)), Starts, Ns),
|
||||||
|
max_list(Ns, Answer),
|
||||||
|
nl, write(Answer), nl.
|
||||||
|
|
||||||
count(Map, X) :-
|
count(Map, X) :-
|
||||||
findall(1, (nth0(_, Map, Row), nth0(_, Row, _-D), \+ D = [0,0,0,0]), Ls),
|
findall(1, (nth0(_, Map, Row), nth0(_, Row, _-D), \+ D = [0,0,0,0]), Ls),
|
||||||
|
Loading…
Reference in New Issue
Block a user