diff options
Diffstat (limited to 'challenge-272/roger-bell-west/lua/ch-2.lua')
| -rwxr-xr-x | challenge-272/roger-bell-west/lua/ch-2.lua | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-272/roger-bell-west/lua/ch-2.lua b/challenge-272/roger-bell-west/lua/ch-2.lua new file mode 100755 index 0000000000..7bf1100382 --- /dev/null +++ b/challenge-272/roger-bell-west/lua/ch-2.lua @@ -0,0 +1,43 @@ +#! /usr/bin/lua + +function split(t) + local cl = {} + string.gsub(t, + "(.)", + function(c) + table.insert(cl, c) + end + ) + return cl +end + +function stringscore(a) + local out = 0 + local c = split(a) + for n = 1, #c - 1 do + out = out + math.abs(string.byte(c[n]) - string.byte(c[n + 1])) + end + return out +end + +if stringscore("hello") == 13 then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if stringscore("perl") == 30 then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if stringscore("raku") == 37 then + io.write("Pass") +else + io.write("FAIL") +end +print("") + |
