more tidy

This commit is contained in:
Alan Evans
2021-12-09 18:06:10 +00:00
parent 9159a85282
commit 0ed26518ac

View File

@@ -60,7 +60,7 @@ get_basins(Low_points, Table) ->
get_basins([], _Table, Basins) -> Basins;
get_basins([Low_point|Rest], Table, Basins) ->
Basin = [Low_point|lists:usort(get_up_slopes([Low_point], Table))],
Basin = [Low_point|get_up_slopes([Low_point], Table)],
get_basins(Rest, Table, [Basin|Basins]).
low_points([H|_] = Table) ->
@@ -76,7 +76,7 @@ get_up_slopes([], _Table, Acc) -> Acc;
get_up_slopes([{X, Y}|Rest], Table, Acc) ->
V = get_value({X,Y}, Table),
Neighbours = [{X+1, Y},{X-1, Y},{X, Y+1},{X, Y-1}],
Up_slopes = lists:filter(fun({X1,Y1}) -> C = get_value({X1,Y1}, Table), C /= 9 andalso C /=10 andalso C > V end, Neighbours),
Up_slopes = lists:filter(fun({X1,Y1}) -> C = get_value({X1,Y1}, Table), C /= 9 andalso C > V end, Neighbours),
get_up_slopes(lists:usort(Rest ++ Up_slopes), Table, lists:usort(Acc ++ Up_slopes)).
is_low_point({X,Y}, Table) ->
@@ -86,7 +86,7 @@ is_low_point({X,Y}, Table) ->
V < get_value({X, Y+1}, Table) andalso
V < get_value({X, Y-1}, Table).
get_value({X,Y}, [H|_] = Table) when X == 0; Y == 0; Y > length(Table); X > length(H) -> 10;
get_value({X,Y}, [H|_] = Table) when X == 0; Y == 0; Y > length(Table); X > length(H) -> 9;
get_value({X,Y}, Table) ->
lists:nth(X, lists:nth(Y, Table)).