blob: 4c8a8a4c92f2123dc5a5a4b7a5b68968847d2725 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
|