From 0ed26518ace56da4fd0c04d77b10877d57b07f20 Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Thu, 9 Dec 2021 18:06:10 +0000 Subject: [PATCH 1/1] more tidy --- day9/day9.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/day9/day9.erl b/day9/day9.erl index ae181db..1906030 100644 --- a/day9/day9.erl +++ b/day9/day9.erl @@ -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)). -- 2.39.2