blob: d9866226403c42616560f5e6950e9369d8eab35f (
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
|
#!/opt/local/bin/lua
--
-- See ../README.md
--
--
-- Run as: lua ch-1.lua < input-file
--
for line in io . lines () do
line = line : gsub ("^[-+]%s*", "")
if line : find ("%D") then
print ("not an integer")
else
if line : len () % 2 == 0 then
print ("even number of digits")
else
if line : len () < 3 then
print ("too short")
else
local start = 1 + (line : len () - 3) / 2
print (line : sub (start, start + 2))
end
end
end
end
|