Created
November 14, 2023 13:07
-
-
Save tatut/8e859c9ed586dd6ef358351d62158588 to your computer and use it in GitHub Desktop.
forest_zipline.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Instead of JSON, encode point of interest data | |
%% as: input([poi(N1, X1, Y1, Z1), ... poi(Nn, Xn, Yn, Zn)]) where Z is the elevation | |
input([poi('Metsäjärvi', 23, 56, 20), | |
poi('Tunturikylä', 78, 12, 120), | |
poi('Sinijärvi', 45, 89, 21), | |
poi('Kallioranta', 34, 67, 19), | |
poi('Karhunpää', 91, 23, 66), | |
poi('Kuusimetsä', 17, 43, 66), | |
poi('Aurinkoniemi', 62, 78, 18), | |
poi('Sammalsaari', 31, 54, 30), | |
poi('Lepakkoluoto', 87, 19, 22), | |
poi('Kultaranta', 53, 76, 23), | |
poi('Revontulijärvi', 29, 61, 24), | |
poi('Hirvimäki', 69, 38, 54), | |
poi('Kielosaari', 48, 82, 26), | |
poi('Karpalojoki', 16, 95, 32), | |
poi('Vuorenjalka', 74, 29, 204), | |
poi('Pajulampi', 37, 50, 28), | |
poi('Kiviranta', 82, 14, 17), | |
poi('Pohjantähti', 59, 73, 444), | |
poi('Pilvimäki', 25, 68, 161), | |
poi('Kuutamokumpu', 96, 41, 17)]). | |
highest_elevation(Max, POIs, Elevation) :- | |
aggregate_all(max(E), (member(poi(_,_,_,E), POIs), E < Max), Elevation). | |
highest_poi(Max, POIs, P) :- | |
highest_elevation(Max, POIs, Elevation), | |
member(P, POIs), | |
P=poi(_,_,_,Elevation). | |
distance(poi(_,X1,Y1,Z1), poi(_,X2,Y2,Z2), Dist) :- | |
Dx is X2 - X1, Dy is Y2 - Y1, Dz is Z2 - Z1, | |
Dist is sqrt(Dx*Dx + Dy*Dy + Dz*Dz). | |
route(Elevation, POIs, []) :- \+ highest_poi(Elevation, POIs, _). | |
route(Elevation, POIs, [HighestPOI|Rest]) :- | |
highest_poi(Elevation, POIs, HighestPOI), | |
HighestPOI = poi(_, _, _, Elevation1), | |
subtract(POIs, [HighestPOI], POIs1), | |
route(Elevation1, POIs1, Rest). | |
total_distance([_], 0). | |
total_distance([P1,P2|Ps], Dist) :- | |
distance(P1, P2, Dist0), | |
total_distance([P2|Ps], Dist1), | |
Dist is Dist0 + Dist1. | |
longest_zipline_travel(Ans) :- | |
input(POIs), | |
aggregate_all(max(Dist), | |
(route(10000, POIs, Route), | |
total_distance(Route, Dist)), | |
MaxDist), | |
Ans is round(MaxDist). | |
% longest_zipline_travel(Ans). | |
% Ans = 1072 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment