diff options
| author | Abigail <abigail@abigail.be> | 2021-02-07 22:33:47 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-02-07 22:33:47 +0100 |
| commit | fe7759f1063d132eb4fe234f95cc25b7d924b6dd (patch) | |
| tree | 7eb3207ce9d1e971e1b4a9789eeee00e63cdb9f5 | |
| parent | 20b322efb8bfcd4055c5f84496e54cde2db3a51a (diff) | |
| download | perlweeklychallenge-club-fe7759f1063d132eb4fe234f95cc25b7d924b6dd.tar.gz perlweeklychallenge-club-fe7759f1063d132eb4fe234f95cc25b7d924b6dd.tar.bz2 perlweeklychallenge-club-fe7759f1063d132eb4fe234f95cc25b7d924b6dd.zip | |
Lua solution for week 98, part 1
| -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 |
