aboutsummaryrefslogtreecommitdiff
path: root/challenge-145/abigail/lua/ch-2.lua
blob: 521f8b0acf47f658ba266566cdf547b287ed187a (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
#!/opt/local/bin/lua

--
-- See ../README.md
--

--
-- Run as: lua ch-2.lua < input-file
--

for line in io . lines () do
    local palindromes = {}
    local out = ""
    for i = 1, #line do
        for j = i, #line do
            local string = line : sub (i, j)
            if string == string : reverse () then
                if palindromes [string] == nil
                then out = out .. string .. " "
                     palindromes [string] = 1
                end
            end
        end
    end
    print (out : sub (1, #out - 1))
end