From 7e7b56db42ceb8d2b8973eae678fa4b58d5d3659 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 13 May 2009 23:32:40 -0500 Subject: add old solutions --- 4.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 4.lua (limited to '4.lua') diff --git a/4.lua b/4.lua new file mode 100644 index 0000000..daec4bc --- /dev/null +++ b/4.lua @@ -0,0 +1,16 @@ +local function is_palindrome(n) + local first_half = string.sub(n, 1, string.len(n) / 2) + local second_half = string.sub(n, -string.len(n) / 2) + return first_half == string.reverse(second_half) +end + +local prods = {} +for i = 100,999 do + for j = 100,i do + table.insert(prods, i * j) + end +end +table.sort(prods, function(a, b) return a > b end) +for _, v in ipairs(prods) do + if is_palindrome(v) then print(v) break end +end -- cgit v1.2.3-54-g00ecf