aboutsummaryrefslogtreecommitdiff
path: root/challenge-096
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-01-23 21:44:49 +0100
committerAbigail <abigail@abigail.be>2021-01-23 21:44:49 +0100
commit1c9975a4c79a02569f92310cf5e30ccd2b542033 (patch)
treef2b10de0a688b25ec73a713749fec42972af6c14 /challenge-096
parent64f66b887a3ce5af2fecbfd49d7107bed36e4c71 (diff)
downloadperlweeklychallenge-club-1c9975a4c79a02569f92310cf5e30ccd2b542033.tar.gz
perlweeklychallenge-club-1c9975a4c79a02569f92310cf5e30ccd2b542033.tar.bz2
perlweeklychallenge-club-1c9975a4c79a02569f92310cf5e30ccd2b542033.zip
Use 'distance' instead of 'distances' for the array name.
Diffstat (limited to 'challenge-096')
-rwxr-xr-xchallenge-096/abigail/lua/ch-2.lua18
-rwxr-xr-xchallenge-096/abigail/ruby/ch-2.rb16
2 files changed, 17 insertions, 17 deletions
diff --git a/challenge-096/abigail/lua/ch-2.lua b/challenge-096/abigail/lua/ch-2.lua
index ef1b039579..99058213ca 100755
--- a/challenge-096/abigail/lua/ch-2.lua
+++ b/challenge-096/abigail/lua/ch-2.lua
@@ -17,13 +17,13 @@
function LevenshteinDistance (first, second)
local n = first : len ()
local m = second : len ()
- distances = {}
+ distance = {}
for i = 0, n do
- distances [i] = {}
+ distance [i] = {}
for j = 0, m do
if i == 0 or j == 0
then
- distances [i] [j] = i + j
+ distance [i] [j] = i + j
else
local cost = 1
if string . sub (first, i, i) ==
@@ -31,10 +31,10 @@ function LevenshteinDistance (first, second)
then
cost = 0
end
- distances [i] [j] = math . min (
- distances [i - 1] [j] + 1,
- distances [i] [j - 1] + 1,
- distances [i - 1] [j - 1] + cost
+ distance [i] [j] = math . min (
+ distance [i - 1] [j] + 1,
+ distance [i] [j - 1] + 1,
+ distance [i - 1] [j - 1] + cost
)
end
end
@@ -46,10 +46,10 @@ function LevenshteinDistance (first, second)
--
if i > 0
then
- distances [i - 1] = nil
+ distance [i - 1] = nil
end
end
- return distances [n] [m]
+ return distance [n] [m]
end
diff --git a/challenge-096/abigail/ruby/ch-2.rb b/challenge-096/abigail/ruby/ch-2.rb
index 931de4f2d7..b7ea2a3f6b 100755
--- a/challenge-096/abigail/ruby/ch-2.rb
+++ b/challenge-096/abigail/ruby/ch-2.rb
@@ -11,24 +11,24 @@
def LevenshteinDistance (first, second)
n = first . length
m = second . length
- distances = []
+ distance = []
for i in 0 .. n do
- distances [i] = []
+ distance [i] = []
for j in 0 .. m do
- distances [i] [j] = i == 0 || j == 0 ? i + j
- : [distances [i - 1] [j] + 1,
- distances [i] [j - 1] + 1,
- distances [i - 1] [j - 1] +
+ distance [i] [j] = i == 0 || j == 0 ? i + j
+ : [distance [i - 1] [j] + 1,
+ distance [i] [j - 1] + 1,
+ distance [i - 1] [j - 1] +
(first [i - 1] == second [j - 1] ? 0 : 1)] . min
end
#
# Release memory
#
if i > 1
- distances [i - 1] = nil
+ distance [i - 1] = nil
end
end
- return distances [n] [m]
+ return distance [n] [m]
end
ARGF . each_line do |_|