From a7cfe19e7988033b8b37d4effedcf01ee203ff0e Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 27 Dec 2021 18:20:34 +0100 Subject: Week 145 --- challenge-145/abigail/lua/ch-2.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 challenge-145/abigail/lua/ch-2.lua (limited to 'challenge-145/abigail/lua/ch-2.lua') diff --git a/challenge-145/abigail/lua/ch-2.lua b/challenge-145/abigail/lua/ch-2.lua new file mode 100644 index 0000000000..521f8b0acf --- /dev/null +++ b/challenge-145/abigail/lua/ch-2.lua @@ -0,0 +1,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 -- cgit