aboutsummaryrefslogtreecommitdiff
path: root/challenge-096/abigail/lua
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-01-19 22:01:14 +0100
committerAbigail <abigail@abigail.be>2021-01-19 22:01:14 +0100
commit053b0ef31a9cddae0cbd792ad539b2d68876538c (patch)
tree06bc9453e9c704e9652149b9832ef55d9f5d0f3d /challenge-096/abigail/lua
parenta7e6309b32bacaac724e734572f4017a6da70448 (diff)
downloadperlweeklychallenge-club-053b0ef31a9cddae0cbd792ad539b2d68876538c.tar.gz
perlweeklychallenge-club-053b0ef31a9cddae0cbd792ad539b2d68876538c.tar.bz2
perlweeklychallenge-club-053b0ef31a9cddae0cbd792ad539b2d68876538c.zip
lua/ch-2.lua: Save some memory.
Diffstat (limited to 'challenge-096/abigail/lua')
-rw-r--r--challenge-096/abigail/lua/ch-2.lua10
1 files changed, 10 insertions, 0 deletions
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