diff options
Diffstat (limited to 'challenge-116/abigail/lua/ch-1.lua')
| -rw-r--r-- | challenge-116/abigail/lua/ch-1.lua | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-116/abigail/lua/ch-1.lua b/challenge-116/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..fadad776fa --- /dev/null +++ b/challenge-116/abigail/lua/ch-1.lua @@ -0,0 +1,39 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua < input-file +-- + +function make_sequence (string, start) + if string == start + then return start + end + if string : find ("^" .. start) + then tail = string : sub (#start + 1, -1) + result = make_sequence (tail, tostring (tonumber (start) + 1)) + if result ~= nil + then return start .. "," .. result + end + result = make_sequence (tail, tostring (tonumber (start) - 1)) + if result ~= nil + then return start .. "," .. result + end + end + return nil +end + +for line in io . lines () do + for i = 1, #line do + start = line : sub (1, i) + result = make_sequence (line, start) + if result ~= nil + then print (result) + goto end_main + end + end + ::end_main:: +end |
