From 053b0ef31a9cddae0cbd792ad539b2d68876538c Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 19 Jan 2021 22:01:14 +0100 Subject: lua/ch-2.lua: Save some memory. --- challenge-096/abigail/lua/ch-2.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/challenge-096/abigail/lua/ch-2.lua b/challenge-096/abigail/lua/ch-2.lua index bb1b042b19..162f06eef0 100644 --- a/challenge-096/abigail/lua/ch-2.lua +++ b/challenge-096/abigail/lua/ch-2.lua @@ -33,6 +33,16 @@ function LevenshteinDistance (first, second) ) end end + + -- + -- We only need the previous row, so we can return the + -- memory of rows before that. This reduces the memory + -- usage from O (n * m) to O (min (n, m)) + -- + if i > 0 + then + distances [i - 1] = nil + end end return distances [n] [m] end -- cgit