diff options
Diffstat (limited to 'challenge-098/abigail/lua/ch-1.lua')
| -rw-r--r-- | challenge-098/abigail/lua/ch-1.lua | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-098/abigail/lua/ch-1.lua b/challenge-098/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..4c8a8a4c92 --- /dev/null +++ b/challenge-098/abigail/lua/ch-1.lua @@ -0,0 +1,34 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua < input-file +-- + +local content = {}; + +function readN (filename, amount) + if content [filename] == nil + then -- + -- Read the content of the file, strip the trailing + -- newline, and store the content in the table 'content' + -- + content [filename] = assert (io . open (filename, "r")) : + read ("*all") : + gsub ("\n$", "") + end + local out = content [filename] : sub (1, amount) + content [filename] = content [filename] : sub (amount + 1) + return out +end + +for line in io . lines () do + -- + -- Split the line on whitespace, call readN() with the + -- result, and print the return value of readN(). + -- + print (readN (line : match ("(%S+) (%S+)"))) +end |
