diff options
| author | Abigail <abigail@abigail.be> | 2021-01-19 22:01:14 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-01-19 22:01:14 +0100 |
| commit | 053b0ef31a9cddae0cbd792ad539b2d68876538c (patch) | |
| tree | 06bc9453e9c704e9652149b9832ef55d9f5d0f3d /challenge-096/abigail/lua | |
| parent | a7e6309b32bacaac724e734572f4017a6da70448 (diff) | |
| download | perlweeklychallenge-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.lua | 10 |
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 |
